![]() |
|
|
| Subject:
Javascript Regular Expression
Category: Computers > Programming Asked by: carpiediem-ga List Price: $3.00 |
Posted:
10 Nov 2005 17:14 PST
Expires: 10 Dec 2005 17:14 PST Question ID: 591694 |
I need a regular expression that will work with Javascript's engine that will meet the criteria below. The easiest way to check if it works is using this page <http://www.regular-expressions.info/javascriptexample.html> The obvious starting point for this is /\(A\)/. The regular expression, in general should match a capital A in parentheses '(A)' but should not match the following cases (9 and z may be any single digit or letter): 'foobar 9. (A) foobar' 'foobar z) (A) foobar' 'foobar ? (A) foobar' 'foobar (A) 9) foobar' 'foobar (A) z) foobar' Payment will be given for a RegExp that matches 'foobar (A) foobar' but not the strings above when using <http://www.regular-expressions.info/javascriptexample.html>. | |
|
|
| There is no answer at this time. |
|
| Subject:
Re: Javascript Regular Expression
From: jeffemminger-ga on 15 Nov 2005 19:02 PST |
works for me:
<script type="text/javascript">
var re = /^[a-z]+ \(A\) [a-z]+$/i;
var s = new Array();
s.push('foobar 9. (A) foobar');
s.push('foobar z) (A) foobar');
s.push('foobar - (A) foobar');
s.push('foobar (A) 9) foobar');
s.push('foobar (A) z) foobar');
s.push('foobar (A) foobar');
var result = new Array();
for (var x = 0; x < s.length; x++) {
result.push( "\"" + s[x] + "\" matches? " + re.test(s[x]) );
}
document.write( "<pre>" + result.join("\n") + "</pre>" );
</script> |
| Subject:
Re: Javascript Regular Expression
From: jeffemminger-ga on 15 Nov 2005 19:03 PST |
the previous example is case-insensitive including the (A) if you want it to be case-insensitive with the exception that (A) must be uppercase, change the pattern to this: var re = /^[a-zA-Z]+ \(A\) [a-zA-Z]+$/; |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |