tags:

views:

76

answers:

4

Can some one suggest regular expression for below text

Signature

text text some more text

text

...

text )

I tried Signature\n.*\) but this only works for

Signature
text )

Basically an expression which starts with a given text, allows multiple new lines, and ends with ).

Thanks

+3  A: 

The problem is that . doesn't match new-lined by default.

A simple option is:

/signature[^)]*\)/i

[^)]* will match all characters besides ).

I'm not sure if you have a Dot-All flag in flex. In JavaScript the /s flag is missing, and the common work around is:

/signature[\s\S]*?\)/i

In this case, you probably want to use a lazy quantifier, *?, so you match until the first ), and not the last.

Kobi
+1 Negated character classes is the way to go.
quantumSoup
A: 

try

var pattern:RegExp = /^Signature.+\\)/m;
noj
Not familiar with Flex's regex API, but shouldn't that be the `s` flag instead of the `m` flag? And is the double backslash necessary?
Bart Kiers
A: 

You can use following regex

\bSignature[\s\S]*?[)]

This regex will first look at Signature, followed by any character which includes alphanumeric characters, \n , etc followed by )

Shekhar
A: 

GNU-Flex supports negated character classes, so you could do:

/* definition section */

%%

Signature[^)]*\) { /* custom code */ }

%%

/* user subroutines */
Bart Kiers