Copy link to clipboard
Copied
Hi,
I am looking for a regexp to for checking a string is containing both the #1 and #3 digits but numbers including these digits are not take in account (12, 368, 51, 6983, etc.);
I couldn't write the expression all at once, so I compiled the search for the digit 1 and the search for the digit 3.
Here is a quick explanation, for finding the digit 1, the regular expression I wrote is:
/(.*[^0-9]1[^0-9].*)/
But that doesn’t work if “1” is at the beginning or at the end of the string, so for testing I add a “x” character at these both places.
And the same for the digit “3”.
Attached is an example of the complete script I wrote.
if (event.value=="") this.getField("light").fillColor=color.transparent;
else if (/(.*[^0-9]1[^0-9].*)/.test("x"+event.value+"x") && /(.*[^0-9]3[^0-9].*)/.test("x"+event.value+"x")) this.getField("light").fillColor=color.green;
else this.getField("light").fillColor=color.red;
I wonder if it's possible to write a single expression for that without adding both characters for testing.
Thanks in advance if somebody has an idea...
@+
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Try this:
/(?=.*(^|\D)1(\D|$))(?=.*(^|\D)3(\D|$))/
Copy link to clipboard
Copied
Great, thanks!
That seems so obvious when we have the solution in front of the eyes...
@+
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more