0

Say I have a string like {{ComputersRule}} and a regex like: [^\}]+. How would I get regular expressions to start at a specified point in the string, i.e. Once it has reached the third character in the string. If it's relevant, and I doubt it is, I'm working in Python version 2.7.3. Thank you.

4

2 回答 2

2

I'd recommend using Python to grab the substring from the third character onwards, and then apply the regex to the rest.

Otherwise, you could just use the regex . (any character except newline) to gobble up the first n characters:

^.{3}([^\}]+)

Notice the ^.{3} which forces the [^\}]+ to not include the first three characters of the string (the ^ anchors to the start of the string/line). The brackets capture the bit you want to extract (so get capturing group 1).

In your particular case, if it's just a case of "I want the text inside the {{ and }}" you could do \{\{([^\}]+)\}\} or [^\{\}]+.

于 2012-07-16T01:45:52.057 回答
1

It appears that what you want to do is to match text within the double braces.

The trick is to specify the braces in the regex but capture the part within. In this case try

\{\{([^}]+)\}\}
于 2012-07-16T01:45:29.357 回答