|
^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{6,}$
- ^ checks for the start of the input string.
- (?=.*[a-zA-Z]) checks that there are at least one letter.
- (?=.*[0-9]) checks that there are at least one digit.
- (?=.*[^a-zA-Z0-9]) checks that there are at least one special character (not a letter nor digit).
- .{6,} checks that there are at least 6 characters.
- $ checks for the end if the input string.
See also
|
|
|
|
|
I need help with regular expression for a javascript I'm working on.
I have some html code into a variable that is named xmlDoc. The string includes a table and there are some things there that I want to pick out with regex.
<tr class="myGreyRow">
<td>6</td>
<td id="fn1">Prentice, Bob</td>
<td>340584305858</td>
<td>Logged out</td>
<td>
<a class="listlink" href="javascript:doEditAgent("56746")">Edit</a>,
<a class="listlink" href="javascript:doRemoveAgent("56746", "fn1")">Delete</a>,
<a class="listlink" href="javascript:doLoginLogout("4", "56746","fn1")">Log in</a>
</td>
</tr>
In this code I want to pick out:
1. The name, "Prentice, Bob"
2. The status, "Logged out"
3. The content from doLoginLogout(), "4", "56746","fn1"
What pattern(s) should I use?
There are five rows similar to this in the table that I need to do this on.
|
|
|
|
|
|
Hi Everyone,
I am trying to figure out how to parse html line and take from it the $ sign and a the monetary value.
For example:
The price of the book is $15.00 and the price of the computer is $1,299.99 cents.
Thank you.
|
|
|
|
|
\$(\d{1,3}(,\d{3})*)(\.\d\d)?
modified on Wednesday, September 7, 2011 10:24 AM
|
|
|
|
|
Thanks for the reply. I doesn't seem to work.
Can you explain briefly what you are attempting to match with that expression?
Thank you.
|
|
|
|
|
It does work. Try this in a console app:
static void Main(string[] args)
{
Regex rx = new Regex(@"\$(\d{1,3}(,\d{3})*)(\.\d\d)?");
foreach (Match m in rx.Matches("This matches $4.12 dollars. It also matches $32.32 or $15 or $2.11 or $0.12 or $156,789.33 or $12,345.67"))
{
Console.WriteLine(m.Value);
}
Console.ReadKey();
}
Output:
$4.12
$32.32
$15
$2.11
$0.12
$156,789.33
$12,345.67
Of course, you must reference the System.Text.RegularExpressions namespace. Also, here is a page you can use to help learn regular expression syntax:
http://www.regular-expressions.info/reference.html
|
|
|
|
|
Thank you for the sample and the link. It works.
|
|
|
|
|
I ran that Regex against your test case and it works perfectly. What output are you getting? What does your code look like that's calling it?
|
|
|
|
|
Member 8216828 wrote: I am trying to figure out how to parse html line and take from it the $ sign and a the monetary value.
In general it isn't a good idea to parse html/xml via regular expressions.
Instead one should use a html/xml parser.
One might use regex if all of the following is true.
1. The source(s) for html/xml are limited. Thus for example there is only one source and there is unlikely to be another.
2. The source is machine generated (thus a library was used to create it rather than an adhoc code of some sort.)
The reason this isn't a good idea is because there are many variations in the way html/xml can be formatted. By the time one has accounted for all of those variances either one has a parser or one has a maintenance problem (or maintenance nightmare).
|
|
|
|
|
Hi Guys,
I have three Regex and would like to know if it's possible to combine them into one.
I'm validating phone numbers in the form:
- 0219081234
- 021 908 1234
- 021-908-1234
here are my regex for the above in order:
- var phoneRegex1 = /^(\d{3})(\d{3})(\d{4})$/;
- var phoneRegex2 = /^(\d{3})(\-)(\d{3})(\-)(\d{4})$/;
- var phoneRegex3 = /^(\d{3})(\ )(\d{3})(\ )(\d{4})$/;
Thanks in Advance,
Morgs
|
|
|
|
|
Just use ? operator
Like this:
^\d{3}-?\s?\d{3}-?\s?\d{4}$
You can flame me whichever way you want and I wouldn't care a bit.
But if you group me with some idiots, I'll turn into your worst nightmare.
|
|
|
|
|
Thanks a ton Firo,
will give it a try...
Morgs
|
|
|
|
|
I think that would match values like:
123456-7890
123456 7890
123456- 7890
123-4567890
123-456 7890
123-456- 7890
123 4567890
123 456-7890
123 456- 7890
123- 4567890
123- 456-7890
123- 456 7890
123- 456- 7890
Which are not in his spec.
|
|
|
|
|
If you want to ensure that the separators (if any) between the groups are the same, I think you need to use a backreference[^].
Something like this perhaps:
(?'Area'\d{3})(?(?=(\s|-))(?'Sep'(\s|-)))(?'Prefix'\d{3})(?(Sep)\k<Sep>)(?'Number'\d{4})
modified on Sunday, July 17, 2011 2:00 PM
|
|
|
|
|
I think this is what you need.
^\d{3}(-|\s)?\d{3}(-|\s)?\d{4}$
|
|
|
|
|
Have a look at this pattern:
^\d{3}[\s-]?\d{3}[\s-]?\d{4}$
modified on Tuesday, August 23, 2011 8:35 PM
|
|
|
|
|
I'm looking for a regex which can match the a value between brackets and deal with a seperator character within.
This is the format I'm after:
[?#?]
where ? can be one or more characters and # is '+', '-' or '='
It should match the following.
[1+1]
[A=T]
[AB=#1#2#3]
So far I've got this:
\[.*[\+-=]?\]
But it doesn't work well, it includes text between the 'tags'.
[A=B]ShouldNotInclude[1=3] (but it does )
I'm obviously doing something wrong,the whole regex probably.
Anyone got an idea?
Found the problem, not the solution.
Problem is that it jumps to the last ']' character it can detect.
modified on Thursday, May 26, 2011 9:15 AM
|
|
|
|
|
Got it:
\[(.*?)[\+-=](.*?)\]
|
|
|
|
|
What you saw is called 'greedy' matching. The better regex engines support non-greedy matching operators, which behave a bit more intuitively, even if they make the regex unreadable!
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
guys;
I use a regular expression such as /(\*\.\w{2,4}( )*,)*( )*\*\.\w{2,4}/ to validate a string like '*.doc, *.docx, *.xls, *.xlsx, *.pdf, *.ppt, *.pps'.
but the validation doesn't sucseed.
what shall i do;
Help people,so poeple can help you.
|
|
|
|
|
Ali Al Omairi(Abu AlHassan) wrote: what shall i do
Make a friend of expresso[^]
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Good tool, man;
100
Help people,so poeple can help you.
|
|
|
|
|
Thank you [EOS]
Help people,so poeple can help you.
|
|
|
|
|
I just started reading about regular expressions and they seem quite complex. So I am going to try really hard to understand them. But I am worried that if I ever want to use regular expressions at work I need to present a format that everyone could understand. So I was thinking something like:
Dim regEx As New RegExBuilder
regEx.MatchStart.SequenceOfText.MatchChar("@").SequenceOfText.MatchChar(".").SequenceOfText(2, 3).MatchEnd
If Not Regex.IsMatch(TextBox1.Text, regEx.GetExpression) Then
MessageBox.Show("This is not a valid email address")
End If
Does that exist or am I saying something really stupid?
I was thinking of making something like that myself, just for fun and to get to know regular expressions myself.
If I succeed and people are interested I could probably put it in an article here on CP too
It's an OO world.
|
|
|
|