0

How to match a pattern that is not after a specified character?

Let's say the specified character is a space and we want to match @match

Eg: @match - finds "@match", because no space before it

@match and @match - finds the first @match but not the second one because there is a space before it.

ANTHING@match - should also find "@match", because no space before it.

stevemao
  • 1,423
  • 1
  • 16
  • 29

2 Answers2

2

Have you tried something like this?

/[^ ](pattern)/

But that won't match patterns at the beginning of the string, so you could use that in combination with:

/^pattern/
colllin
  • 9,442
  • 9
  • 49
  • 65
1

I'm not sure... but for all trying to answer this question, here's a jsfiddle where you can just enter your REGEX where it says INSERT_REGEX_HERE and see if it works. Enjoy!

<div ng-app>
<form novalidate name="myForm">
<input name="input1" type="text" ng-model="input1" ng-pattern="/INSERT_REGEX_HERE/" />
<div ng-show="myForm.input1.$dirty && myForm.input1.$error.pattern">DOES NOT MATCH     REGEX</div>
</form> 
</div>

http://jsfiddle.net/MLhqT/2/

stackPusher
  • 6,076
  • 3
  • 35
  • 36