-2

I have a code of line as:

Pattern pattern = Pattern.compile("^\\d{1,4}\\,(.*?),");

I want to understand what exactly is getting done in above regular expression,i.e.

"^\\d{1,4}\\,(.*?),"
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • It will match strings that begin with 1-4 digits, followed by `,` followed by one optional character, followed by a `,`. You can use [regex101.com](https://regex101.com/r/VIGYhg/1) to explore and understand regular expressions. – stackprotector Apr 29 '20 at 05:59
  • Does this answer your question? [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – tripleee Apr 29 '20 at 07:45

1 Answers1

1
^\d{1,4},(.*?),

Explaination:

  • ^\d{1,4} -- means must begin with between 1 to 4 digits (characters between 0 and 9)...
  • \, -- means then there have ,
  • (.*?) -- means there will be any character 0 or more times but will happen 0 or 1 time...
  • , -- means there is one more ,

Look at this demo.. you will get better explaination here

Look at this answer to learn about regex.....

GolamMazid Sajib
  • 8,698
  • 6
  • 21
  • 39