Yes, I know this sounds counter-intuitive. But I need it for a JavaScript mashup written by someone else. There is a regex value used to select project names to which the mashup will apply. I want it to apply to all projects.
4 Answers
OK, folks. I'm not strong with regex, but I think I figured this out. I'm just using the following regex:
'.*'
This is working fine for me. The dot allows any character, and the asterisk allows it to be repeated any number of times.
If anybody knows how to limit this to a string that is a single line (ASCII Character set) I'm all ears.

- 8,949
- 10
- 51
- 76
Your answer (.*
) works, and by default will match only a single line. If you wanted it to match multiple lines, you could enable multi-line mode in your particular regex implementation, but nobody enables it by default AFAIK.

- 9,557
- 2
- 31
- 39
-
If those parens were included in the code block, this would be spot on – danseery Jun 25 '12 at 18:57
You're correct that .*
will find any character, however, the exception are newline characters ('\n', etc). What you could try is grouping. This: (.*)
should work for you. If you need help with accessing matched group more info can be found here: How do you access the matched groups in a JavaScript regular expression?
EDIT: If you are using something other than JavaScript the implementation may differ slightly with multi vs single-line mode. JavaScript itself does not have single-ling mode.
As others have mentioned, the .
doesn't match line feeds.
If you must match absolutely every character including \n
then you can use this instead...
[\s\S]*
That's whitespace characters, and non-whitespace characters. In other words, that'll match everything.

- 21,740
- 5
- 68
- 90