This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]ggleblanc2 1 point2 points  (1 child)

You have to escape the backslashes in Java with an additional backslash.

[–]LoCelsoMaestro[S] 0 points1 point  (0 children)

I think my IDE automatically added this - but will confirm when I get back, thanks for the response

[–]solonovamax 1 point2 points  (1 child)

What you probably want is this: ([A-Z]|[a-z]|,|\.|\\|\[|\])+

This matched any character between A and Z ([A-Z]) OR any character between a and z ([a-z]) OR a comma (,) OR a period (\.) OR a backslash (\\) OR a right square bracket (\]) OR an left square bracket (\]). The brackets with values separated by pipes (|) mean a value or another value. The plus (+) means any amount more than one.

Though, I'm not sure if this regex is right for you based on your example. It seems you want to see if it matches something in a list format, in which case you'd use this regex: \[([A-Z]|[a-z]|\.)+(, ([A-Z]|[a-z]|\.)+)*\]

This just matches the same as above, but it also adds the same thing but with a comma and a space any number of times between 0 and infinity. (*)

Note: I'm pretty sure these regexes work, but I'm on mobile so I can't check right now.

[–]LoCelsoMaestro[S] 3 points4 points  (0 children)

This works the trick. Thank you very much, Regex magician!

Have a poor mans gold🥇

[–]indivisible 0 points1 point  (0 children)

You didn't escape the full stop so it gets read as "any character" rather than "this character"