2

Here is the string i am trying to match

"NNNN.[LOOP]S[SENSOR] [TEXT]"

Here is the RegEx i am using

"NNNN.([^\n\r/.]*)S([^\n\r/.]*) ([^\n\r/.]*)"

I want this to match "[LOOP]", "[SENSOR]" and "[TEXT]"

However it matches "[LOOP]S[SEN", "OR]" and "[TEXT]"

Please send help

2
  • Learn about "greedy regular expressions": regular-expressions.info/repeat.html Commented Mar 20, 2014 at 2:45
  • 2
    Try matching the square brackets in your regular expression. Commented Mar 20, 2014 at 2:46

1 Answer 1

3

Try this one:

NNNN\.(\[[^\s]+\])S(\[[^\s]+\])\s(\[[^\s]+\])

Note that you have to escape the dot "." and the square brackets "[" "]"

This will match: NNNN string, followed by a dot \. followed by a string (that doesn't contains spaces) between brackets (\[[^\s]+\]), followed by an S, followed by another string between brackets (\[[^\s]+\]), followed by a single space \s, followed by a third string between brackets (\[[^\s]+\]).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.