Hello everyone, i've looked for C#/regex around the net, but i've yet to find something which would be appropriate for my situation ( my question will concern regular expressions more than C# itself, though i also need the C# syntax for this ).
I have a string which, after some modifications done to it, needs to match a certain pattern. Problem is, the pattern seems to me a bit more complicated than regular....regular expressions. I'll explain it in words:
The string needs to look like this:
One square bracket [
At least 1 number and at most 7
A variable ( hold on, i'll explain ! ) number of ' | ' characters
And, finally, a closing square bracket ]
The idea is, the string MUST have 10 characters, no more, no less.
2 of them are the brackets []
1-7 of them are numbers
the rest are |||| characters ( -> there will be between 1 and 7 ' | ' characters)
Obviously, my issue is related to the string max length, and the ' | ' fill-up characters.
Any help will be appreciated. Thank you.
C# Regular Expressions
Started by totonex, Dec 11 2009 02:28 PM
4 replies to this topic
#1
Posted 11 December 2009 - 02:28 PM
|
|
|
#2
Posted 11 December 2009 - 03:17 PM
Regex is actually my really weak spot :-)
Here is one cool link (choose Advanced Regex syntax link on page):
Regular Expressions Reference - Basic Syntax
I could ask my co-workers on monday for a solution if it's not too late? :-)
And here's another cool regex tester:
Derek Slager: A Better .NET Regular Expression Tester
Here is one cool link (choose Advanced Regex syntax link on page):
Regular Expressions Reference - Basic Syntax
I could ask my co-workers on monday for a solution if it's not too late? :-)
And here's another cool regex tester:
Derek Slager: A Better .NET Regular Expression Tester
#3
Posted 12 December 2009 - 03:31 AM
Thank you very much, will look at those links, meanwhile i will further exemplify my irregular...regular expression needs:
[123|||||]
[4556786|] - This is actually the maximum number length. Hence, there will always be a '|' terminating character.
[4|||||||] - Minimum number length.
Note, in every case, the total length of the string is 10.
[123|||||]
[4556786|] - This is actually the maximum number length. Hence, there will always be a '|' terminating character.
[4|||||||] - Minimum number length.
Note, in every case, the total length of the string is 10.
#4
Posted 12 December 2009 - 05:13 AM
Why not do the obvious regex match, and also test the length?
"[(0-9){1,7}\|*]"
I haven't tested the regex, so it may need some tweaking, but that plus a general length test should do the job.
"[(0-9){1,7}\|*]"
I haven't tested the regex, so it may need some tweaking, but that plus a general length test should do the job.
#5
Posted 12 December 2009 - 11:11 AM
Thanks guys :D:D
Don't bother anymore - i found a workaround. Instead of completing the missing numbers with ||| [45||||||], i completed the section preceding the number with zero's [00000045] ( since i only needed the number between the brackets ). Padded left with zero's, and tested with this: @\[[0-9]{8}\] . Worked great :D
Don't bother anymore - i found a workaround. Instead of completing the missing numbers with ||| [45||||||], i completed the section preceding the number with zero's [00000045] ( since i only needed the number between the brackets ). Padded left with zero's, and tested with this: @\[[0-9]{8}\] . Worked great :D


Sign In
Create Account


Back to top









