0

I am trying to make a regex pattern which matches a word/character a space and then comma seperated values with or without spaces before and after. I have found difficulty making a pattern which did this and was wondering if someone could help me. Example of what it should match: ages 19, 43,91

I was trying something like this, "(^[^\s])([^,]+)+", but it only matched the first one.

1 Answer 1

1

You can try pattern:

\S+(?:\s*\d+\s*,?)+ 

Regex demo.


  • \S+ - this will match one or more non-whitespace characters

  • (?:\s*\d+\s*,?)+ - non-capturing group.

    • \s* - match 0 or more whitespace characters

    • \d+ - match 1 or more digits

    • \s* - match 0 or more whitespace characters

    • ,? - optionally match ,

  • + - You may repeat this non-capturing group 1 or more times

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.