What is the regex validation for positive and negative numbers?
Adding -? will do the trick:
^-?[1-9]+([0-9]+)*$
regex pattern to allow positive and negative integers
Assuming you only mention an optional negative sign in front of the number:
xs:pattern value="-?[0-9]{0,10}"
Regex to match positive or negative number or empty string, but not '-' alone
You may make the digits obligatory and enclose the whole number matching part with an optional group:
/^(?:-?\d+)?$/
See the regex demo
Details
^
- start of the string(?:-?\d+)?
- an optional non-capturing group matching 1 or 0 occurrences of:-?
- an optional-
\d+
- 1 or more digits
$
- end of string.
Regex to match positive and negative numbers and text between "" after a character
You may read the file into a string and run the following regex:
var matches = Regex.Matches(filecontents, @"(?m)^\*\w+[\s-[\r\n]]*""?(.*?)""?\r?$")
.Cast<Match>()
.Select(x => x.Groups[1].Value)
.ToList();
See the .NET regex demo.
Details:
(?m)
-RegexOptions.Multiline
option on^
- start of a line\*
- a*
char\w+
- one or more word chars[\s-[\r\n]]*
- zero or more whitespaces other than CR and LF"?
- an optional"
char(.*?)
- Group 1: any zero or more chars other than an LF char, as few as possible"?
- an optional"
char\r?
- an optional CR$
- end of a line/string.
Related Topics
How to Get the Ajax Response from Success and Assign It in a Variable Using Jquery
How to Hash Passwords Before Posting and Then Using Bcrypt
How to Get the Index from a Json Object With Value
How to Compress an Image Via JavaScript in the Browser
How to Refresh Specific Div Using Javascript/Jquery With the Variables on It
Making a JavaScript Function That Finds the First Word in a String/Sentence
How to Use Owl Carousel Vertically
Uncaught Typeerror: $(...).Modal Is Not a Function
Resize a Base-64 Image in JavaScript Without Using Canvas
Different Color for Each Bar in a Bar Chart; Chartjs
Stop Just One Dropdown Toggle from Closing on Click
Javascript Generate Video Thumbnail from Video Url
Calculate and Display % Discount for Price Classes JavaScript
Node.Js MySQL Query in a for Loop
Use Localstorage Across Subdomains
How to Filter Date Range in Datatables