-1

How can I know that any particular regular expression matches which type of input? Like I want to know about \$\{([\w]+)\}. Which string will be matched by this regular expression?

Pattern placeholder = Pattern.compile("\\$\\{([\\w]+)\\}");
Matcher mat = placeholder.matcher("input");
while (mat.find()) {

}
Muhammad Imran Tariq
  • 20,100
  • 42
  • 115
  • 186
  • 1
    [What does the regex mean](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean)? – Wiktor Stribiżew Aug 27 '15 at 09:40
  • 1
    To know what a regex matches, go to [regex101.com](http://regex101.com) and type in something, modify, experiment, pay attention to the right-hand pane with explanation and read those hints carefully. – Wiktor Stribiżew Aug 27 '15 at 09:46

2 Answers2

2

It accepts E.L access type to variables:

${somethingHere}

As comemnted above, you can check that Reference for more info.

Community
  • 1
  • 1
Fran Montero
  • 1,581
  • 10
  • 21
2

This will find any character within ${}

The \w metacharacter is used to find a word character.

A word character is a character from a-z, A-Z, 0-9, including the _ (underscore) character.

The other characters are escaped by \, \$ looks for a $ \{ looks for { and \} looks for }

The + token mean to repeat the character ([\w]) between one and unlimited times, as many times as possible.

KAD
  • 10,375
  • 4
  • 25
  • 60