views:

94

answers:

5

I know JavaScript regular expressions can ignore case for the entire match, but what about just the first character? Then hello World! would match Hello World! but not hello world!.

+3  A: 

You mean like /[Tt]uesday/

The [Tt] creates a set, which means either 'T' or 't' can match that first character.

Eli
This question had zero answers when I clicked on it. Now two. I fail to snipe easy points yet again :(
erisco
+2  A: 
[a-zA-Z]{1}[a-z]
Ben
the word may contain capitals and punctuation
Plumo
That's a direct contradiction of the requirements as stated in your question.
Tim Pietzcker
@Richard, can you provide me some examples?
Ben
+1  A: 
polygenelubricants
+2  A: 

Your question doesn't really make sense. Since the edit, it now says "I am after a general regular expression that can be applied to all words.". The regex to match all words and punctuation would be ".*"

What are you trying to match? Can you give examples of what should match and what should not match?

Zarigani
This should be a comment. Thank you.
Kobi
+2  A: 

Do it another way. Force the first character of your data string to lower case before matching it against your regular expression. Here's how you'd do it in ActionScript, JavaScript should be similar:

var input="Hello World!";
var regex=/hello World!/;
var input2 = input.substr(0, 1).toLowerCase() + input.substr(1);
trace(input2.match(regex));
davr
yeah, guess I'll just do it directly
Plumo