regex expressions

  • Thread starter Thread starter Bert
  • Start date Start date
B

Bert

hi


How do I make a regex to find a word that starts en ends with a certain
letter. What is in between is random.

thanks

b
 
hi


How do I make a regex to find a word that starts en ends with a certain
letter. What is in between is random.

thanks


You can try this:

(en(\w){1,}g)

This will find en with one one or more letters in between and ending in g.

i.e. ending, encoding, encrypting, etc.
 
Bert,

Are this kind of not better options,

If a(0) = "j" And a(a.Length - 1) = "j" Then

At least it is 50 times quicker than Regex.

Cor
 
Yes,

But a REGEXP can parse a whole text at once. And you forgot in your example
code to include a logic to split the text for all words. And your code
should also make sure that all words are split correctly at the ending and
the beginning of a word boundry... So your code will grow quite complex very
fast. And if you handle all those special cases, then i am not sure if you
are really faster then a RegExp. Also the .NET Regexp engine is quite fast!


And I would suggest a slightly different regexp..

(en(\w){1,}g)
-> will also match "whateverending" but it will only return "ending"
(Hint: use word boundrys in your match)

Another match could be "... encodingsession ..."
-> "encoding"
(Hint: use lazy quantifiers... Regexp matches are greedy by default)

For a good summary of what you can do I would suggest
http://www.regular-expressions.info/quickstart.html


So much for fussing about the other regexp, and here is my own suggestion :)

\b(en(\w)*?g)
\b = beginning of a word , followed by a literal "en" , followed buy as many
"letters" as needed, and must be ending with a "g"
 
rdrunnner,

My meaning was telling not to use it, but think twice if there is not a more
simpler solution.

I see now that it could be understand wrong.


Cor
 
doh,

My meaning was not telling: "not to use it" but to think think twice if
there is not a more simpler sollution.

Cor
 
Bert,

Are this kind of not better options,

If a(0) = "j" And a(a.Length - 1) = "j" Then

At least it is 50 times quicker than Regex.

RegEx is elegant and extendable - it's built for text parsing.
 
Back
Top