matching strings that start with (

2 views
Skip to first unread message

jc

unread,
Nov 19, 2009, 7:35:10 AM11/19/09
to Regex
The regex in this Javascript is not working to find strings that
start with "(". Escaping the ( and using chr(40) did not work either.
I confirmed strings that match are being sent. And if I change my
match to another character like "-" it works.

How do I do this?

if (strTitle.match("^"+"("))
{
alert("found");
}


Thanks.

inhahe

unread,
Nov 19, 2009, 7:45:58 AM11/19/09
to re...@googlegroups.com
JavaScript is probably interpreting the escape sequence and then feeding "(" into the regex machine.
You may have to try doing "\\("


--

You received this message because you are subscribed to the Google Groups "Regex" group.
To post to this group, send email to re...@googlegroups.com.
To unsubscribe from this group, send email to regex+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/regex?hl=.



jc

unread,
Nov 19, 2009, 8:22:20 AM11/19/09
to Regex


On Nov 19, 7:45 am, inhahe <inh...@gmail.com> wrote:
> JavaScript is probably interpreting the escape sequence and then feeding "("
> into the regex machine.
> You may have to try doing "\\("
>

I did.. no luck.

Eugeny Sattler

unread,
Nov 19, 2009, 10:08:03 AM11/19/09
to re...@googlegroups.com
RegexBuddy advises such syntax:

if (/^\(.*$/im.test(subject_string)) {
alert("found");
} else {
alert("not found");
}

jc

unread,
Nov 19, 2009, 10:27:18 AM11/19/09
to Regex
I tried this..
if (/^\(.*$/im.test(strTitle)) {


But it did not work. Not that I understand that code.

On the subject of Regex buddy..

I tried testing

"^"+"\("
against this string
(TEST)

here
http://www.regexplanet.com/simple/index.html

and it fails.

That reminds me.. anybody know of a good online web based regex
builder? Sure would be nice to have one.

Thanks.

jc

unread,
Nov 19, 2009, 10:43:54 AM11/19/09
to Regex

what's interesting is testing this regex

^\(

against this string

(TEST

on these two regex test site .. one matches, one doesn't


http://regexpal.com/
http://www.regexplanet.com/simple/index.html


I tried ^\( and ^\\( in my javascript code and neither works.

surely, there is a way around this.

Jan Goyvaerts

unread,
Nov 19, 2009, 7:18:09 PM11/19/09
to Regex
In JavaScript, this regex:

/^\(.*$/m

matches a complete string if it starts with a (. If the string has
embedded line breaks, it matches the first line in the multi-line
string that starts with a (

This regex:

(/^\(/m

matches ( at the start of a line.

The RegexBuddy source code snippet shown above returns true/false
depending on whether a match can be found within the string.

regexplanet.com does find the match. You have to look at the find()
column. matches() is a Java fuction that requires the regular
expression to match the whole string. Don't do your testing with a
Java regex tester when using JavaScript.

If these regexes aren't working, the problem is elsewhere in your code.

Eugeny Sattler

unread,
Nov 19, 2009, 10:54:30 PM11/19/09
to re...@googlegroups.com
Tested in Free JavaScript Editor by Yaldex Software (www.yaldex.com)
and it matches OK.
See attached screenshot.
YaldexFreeJS_Editor.png
Reply all
Reply to author
Forward
0 new messages