Regular Expression for Match Pattern (string) Function 
Author Message
 Regular Expression for Match Pattern (string) Function

I need to find a variable length string enclosed by brackets and
within a string. Can't seem to get the regular expression right for
the Match Pattern function.  I'm able to get the job done using the
Token function, but it's not as slick or tight as I'd like.  Does
anybody out there have the expression for this?


Mon, 21 Jun 2004 22:06:07 GMT  
 Regular Expression for Match Pattern (string) Function
The regular expression is "\[[~\]]*\]" which means:
look for a bracket "\[" (\ is the escape char)
followed by a string not containing a closing bracket "[~\]]*"
followed by a closing bracket "\]". The match string include the
brackets

You can also read "Scan from String" with the following format:
"%[^\[]\[%[^\[\]]" and read the 2nd output. The brackets are removed
from the scanned string.



Tue, 22 Jun 2004 00:15:19 GMT  
 Regular Expression for Match Pattern (string) Function

Quote:

> The regular expression is "\[[~\]]*\]" which means:
> look for a bracket "\[" (\ is the escape char)
> followed by a string not containing a closing bracket "[~\]]*"
> followed by a closing bracket "\]". The match string include the
> brackets

> You can also read "Scan from String" with the following format:
> "%[^\[]\[%[^\[\]]" and read the 2nd output. The brackets are removed
> from the scanned string.

Thanks, Jean_Pierre

I did some more experimenting after posting and found that \[.*\] also
works with the match pattern function.  Thanks for your input.

sm



Tue, 22 Jun 2004 22:13:23 GMT  
 Regular Expression for Match Pattern (string) Function
This RE, "\[.*\]" matches the *longest* string included in brackets.
If your string has many bracketed expression, for example "AB [CD] EF
[GH] IJ", the matched string returned is "[CD] EF [GH]" (from the
first left bracket to the last right braket)which may not be the
desired result.
That is why in the RE "\[[~\]]*\]" the right bracket is excluded from
the search pattern.


Wed, 23 Jun 2004 23:05:02 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Regular expression string pattern matching: Embedding pop-11 procedures, and more

2. iss-matching - the free Regular Expression / Pattern Matching cluster

3. Bug in regular expression pattern matching?

4. Pattern-matching regular-expression algorithm?

5. Regular Expression Pattern Matching "State" Object

6. Regular expressions, pattern matching

7. pattern matching using regular expressions

8. Need code to match strings with regular expressions

9. problem with string match and regular expression

10. Alternative strings in Match Pattern function

11. regular expression matching in J ? (or APL)

12. Regular Expression to match HTML elements

 

 
Powered by phpBB® Forum Software