Google Answers Logo
View Question
 
Q: Javascript Regular Expression ( No Answer,   2 Comments )
Question  
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>.

Clarification of Question by carpiediem-ga on 16 Nov 2005 08:11 PST
What you posted does meet the criteria of my post and I'd be happy to
pay you for it, but it doesn't really help me.  If you'd like to dive
a little deeper, I meant foobar to be a placeholder not only for
letters, but punctuation, numbers and whitespace as well.  I also
can't count on foobar being more than one character or on it being
near the beginning or end of a test string.  If this wasn't
javascript, the negative look-ahead and look-behind notation should be
perfect.  However, I am am constrained by the language.

Once again, if you want the $3, I think you need to claim the answer,
not just a comment, but if you have other ideas I'd love to hear them.
Answer  
There is no answer at this time.

Comments  
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]+$/;

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

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 Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy