I am trying to match a string in the following form:
require([ "foo/bar", "foo2/bar2" ])
Whitespace should be ignored entirely. I am using the following regex with little success:
require\\(\s*\\[[.\s]*\\]\\)
Any suggestions? I know that regex attempt is horrible…
EDIT: I am using Python!
If you are using Java or PHP with double-quoted strings or somethig similar, you need to double escape the
\sas well. If not, then you need to remove all double backslashes instead (and make them single backslashes). Also note, that[.\s]matches only periods and whitespace (.loses its wildcard meaning within character classes). If you really want to match anything use[\s\S]instead.Assuming double escaping is required in the language you use:
Note that this will cause problems if this occurs multiple times in the same string. Then you would get a match from the first
require([to the last]). To avoid this, disallow]within the repetition. However, be aware that this in turn can cause problems if your strings withinrequiremay contain]themselves: