-1

Here is the regex I'm looking at. I I've breaken it down into parts & am trying to understand what the below means .

^(\\s*\\[abc.*?)(\\])

This regex:

^- start of line
\\ --> matches \
s* --> matches character s ( 0 to unlimited times)
\\--> matches \

[abc.*?)(\\] --- I'm not sure what does this match exactly?
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525

3 Answers3

1

Double \\ mess is for Java. Remove one from there and try again explaining.

^(\s*\[abc.*?)(\])

Now the explanation again:

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    \s*                      whitespace (\n, \r, \t, \f, and " ") (0
                             or more times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
    \[                       '['
--------------------------------------------------------------------------------
    abc                      'abc'
--------------------------------------------------------------------------------
    .*?                      any character except \n (0 or more times
                             (matching the least amount possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  (                        group and capture to \2:
--------------------------------------------------------------------------------
    \]                       ']'
--------------------------------------------------------------------------------
  )                        end of \2
Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
0
^(\\s*\\[abc.*?)(\\])

is a regular expression that is escaped for use in a Java string. After unescaping (after it's compiled by the java.util.regex.Pattern), it's

^(\s*\[abc.*?)(\])

Each piece:

^

is a ^:start of line/input anchor

(

is the start of a capture group

\s*

is *:zero or more \s:whitespace characters

\[abc

is the literal string [abc. The open-square-bracket is literal because it's escaped. Were it not escaped, it would be a special character indicating the start of a character class.

.*?

is a reluctantly zero or more of any character

)

is the end of the capture group

(\])

is another capture group with a single literal close-square-bracket (literal because it's escaped).


All links in this answer are from the Stack Overflow Regular Expressions FAQ.

Community
  • 1
  • 1
aliteralmind
  • 19,847
  • 17
  • 77
  • 108
0

Pictorial representation from debuggex beta

enter image description here

Braj
  • 46,415
  • 5
  • 60
  • 76