javascript - Cant quite get my JS regex to work with wildcrd -


iv been trying js regex match as follows:

"some string stuff [other string stuff] more string stuff"

the '[' , ']' characters optional. text between not optional (and can single alphanumeric or full sentence). far i've come (and many iterations of other ideas in between):

/^(some string stuff \[?.*\]? more string stuff)$/gim 

note 'gim' arguments i'm testing line line, finding matches , ignoring case. every test seems frustratingly work not quite, regex fu not strong seems! iv trawled through other forum posts , likewise work not quite after tinkering. appreciated!

edit

the "some string stuff " @ start , " more string stuff" @ end mandatory string valid. text between them has variance; ie long not line break.

examples of valid text:

some string stuff [other string stuff] more string stuff string stuff other string stuff more string stuff string stuff string more string stuff string stuff [string] more string stuff 

examples of invalid text:

some string stuff more string stuff string stuff [] more string stuff string stuff  more string stuff string stuff \n more string stuff 

/^([a-za-z ])+([\[]?)[a-za-z ]+([\]]?)([a-za-z ]+)/gim 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -