How can i detect string is start with "+"
I tried
^\s*?\+.*$
but no help.
P.s: I have only one line alltime.
How can i detect string is start with "+"
I tried
^\s*?\+.*$
but no help.
P.s: I have only one line alltime.
You don't need \s*?
, you have to use:
^\+
or...
^[+]
In case you want to check a complete string, you can use:
^\+.*$
Without regex, you can also use native method startsWith()
.
So it would be:
var str1 = '+some text';
var bool = str1.startsWith('+'); //true
^\+.*$
should work for your purposes.
Here's a fiddle with a couple test strings : https://regex101.com/r/nP2eL7/1
Here's an optional (and optimal) solution in the case that the first character of your string happens to be either a +
or -
and you don't want the proceeding number to have any leading zeros:
/(?<=^\+|-|^)[1-9]\d*/