|
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.
|
|
|
|
|
|
|
Naerling wrote: I was thinking of making something like that myself
Well, go, man, go! It looks like a fun exercise. You could certainly start with just the parts you need now and add more as needed. You may need to leave out more "advanced" stuff like nested groups, but just encapsulating the most basic functionality may be of use to many.
|
|
|
|
|
I read some articles about regular expressions, that much all strings except matched, but I can't get it working.
In our system we have numeric user names. They are in form "99/999/999", where "9" is of course any number. We want to control access to some functionalities by using regular expressions. I mean we have a table with two columns, one contains regular expression, that matches some numbers, and second column contains a code, that informs, which functionality is available. So if we want users, that have numbers starting with "01" to access functionality "Functionality1", we have entry:
01/[0-9]{3}/[0-9]{3}, Functionality1 .
But there's a functionality, that is inaccessible by a group of users, that have a number, that starts with 23/123/. And I can't figure out how to do it (in a simple form). The only thing I can make working is to combine ranges. So I have something like:
([0-1][0-9]/[0-9]{3}/[0-9]{3})|(2[0-2]/[0-9]{3}/[0-9]{3})...
And this way I can combine a number of ranges to match only those, I want to match. But this makes it quite difficult to check for errors and modify. How can I make a regex, that excludes all numbers, that start with 23/123 without specifying all ranges, that are allowed?
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
The exact details depends on which regex engine you are using, but in most, the construct [^2-5] for example would match any character NOT in the range 2 to 5 inclusive. Give it a try with your favourite regex tester. (There are some good ones online.)
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
I'm using .NET built-in engine. I tried, but it ends up with very complicated expression. I think we'll try to find another solution.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
I know this is probably not the answer you are looking for, but you can add a third column to your table of type boolean. Then you can make decisions to allow or deny access to functionality-X based on the content of your regexp and the flag: if the flag is set, the expression must match in order for the functionality to be available; if the flag is not set, the expression must not match in order for the functionality to be available. In other words, functionality is available only when regexp.IsMatch is equal to the flag from the table. This will improve your maintainability as well, because the target regexps will be a lot more readable.
|
|
|
|
|
If we didn't redesign our solution, this would probably be our course of action. So (although I won't use your solution ), I'm giving you a "5".
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
Could you help me write a pattern for Regex.
I need to look for file name with this pattern:
string(no number; only 100 characters)-6digitnumber_string
|
|
|
|
|
what have you done so far?
and can you clarify with some positive and negative examples?
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Off the top of my head, this one should suffice:
([a-zA-z]{100}\d{6}[a-zA-Z]{1,})
|
|
|
|
|
examples:
Testing-123456_filename.xls - valid
My-1234568_filename.txt- not valid (because 7 digits)
Testring-123456-filename.dat- not valid( missing _)
filename.txt - not valid( missing _ and - )
Testring_123456_filename.dat- not valid( missing -)
|
|
|
|
|
This doesn't match what you specified originally. You stated that it should be 100 characters, but My-, for instance, isn't. So, which set of rules are correct?
|
|
|
|
|
clarification:it can be up to 100 charachers
|
|
|
|
|
Then try this:
[a-zA-Z]{1,100}-\d{6}_[a-zA-Z]{1,}
|
|
|
|
|
WORKING!!!!!!!!!! THANK YOU
|
|
|
|
|
-\d{6}_
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
If I used you pattern I am getting all invalid returns
Here my code and test cases:
Public Function Verify(ByVal myFileName As String)<br />
Dim Pattern As String = "-d{6}_"<br />
'"([a-zA-z]{100}\d{6}[a-zA-z]{1,})"<br />
Dim MyRegex As New RegularExpressions.Regex(Pattern, RegularExpressions.RegexOptions.IgnoreCase)<br />
Return MyRegex.IsMatch(myFileName, 0)<br />
End Function
Testing scenario:
If Verify("Granic-012345_Test-Granic.txt") Then ' should be valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If<br />
If Verify("TESTTING-123456-Norman_NDtest1.dat") Then ' should be not valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If<br />
If Verify("GRANIC-123456_jayson.xls") Then ' should be not valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If<br />
If Verify("incoming-testfile.txt") Then ' should be not valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If<br />
<br />
If Verify("Testing-474948_filename.txt") Then ' should be valid<br />
MessageBox.Show("valid")<br />
Else<br />
MessageBox.Show("Not valid")<br />
End If
|
|
|
|
|
that is a useless message: a lot of code, but no results.
and code should be in PRE tags, not CODE tags.
it would help if you would copy my suggestion correctly.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|