Home All Groups Group Topic Archive Search About
Author
23 Dec 2006 1:54 AM
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

Author
23 Dec 2006 4:08 AM
Spam Catcher
"Bert" <bef***@gmail.com> wrote in news:#7kvRVjJHHA.320
@TK2MSFTNGP06.phx.gbl:

> 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.
Are all your drivers up to date? click for free checkup

Author
23 Dec 2006 4:56 AM
Cor Ligthert [MVP]
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

Show quoteHide quote
"Bert" <bef***@gmail.com> schreef in bericht
news:%237kvRVjJHHA.320@TK2MSFTNGP06.phx.gbl...
> 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
>
Author
23 Dec 2006 9:34 AM
rdrunner
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"


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:Olfdy5kJHHA.1468@TK2MSFTNGP04.phx.gbl...
> 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
>
> "Bert" <bef***@gmail.com> schreef in bericht
> news:%237kvRVjJHHA.320@TK2MSFTNGP06.phx.gbl...
>> 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
>>
>
>
Author
23 Dec 2006 9:46 AM
rdrunner
EDIT: Ignore my 2nd "Hint"

I had another example 1st and i forgot to remove the line ;)

Show quoteHide quote
"rdrunner" <N***@your.com> wrote in message
news:ODltIWnJHHA.3872@TK2MSFTNGP06.phx.gbl...
> 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"
>
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:Olfdy5kJHHA.1468@TK2MSFTNGP04.phx.gbl...
>> 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
>>
>> "Bert" <bef***@gmail.com> schreef in bericht
>> news:%237kvRVjJHHA.320@TK2MSFTNGP06.phx.gbl...
>>> 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
>>>
>>
>>
>
Author
23 Dec 2006 5:09 PM
Cor Ligthert [MVP]
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

Show quoteHide quote
"rdrunner" <N***@your.com> schreef in bericht
news:ODltIWnJHHA.3872@TK2MSFTNGP06.phx.gbl...
> 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"
>
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:Olfdy5kJHHA.1468@TK2MSFTNGP04.phx.gbl...
>> 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
>>
>> "Bert" <bef***@gmail.com> schreef in bericht
>> news:%237kvRVjJHHA.320@TK2MSFTNGP06.phx.gbl...
>>> 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
>>>
>>
>>
>
Author
23 Dec 2006 5:27 PM
Cor Ligthert [MVP]
doh,

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

Cor

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schreef in bericht
news:%23A2WFTrJHHA.3952@TK2MSFTNGP02.phx.gbl...
> 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
>
> "rdrunner" <N***@your.com> schreef in bericht
> news:ODltIWnJHHA.3872@TK2MSFTNGP06.phx.gbl...
>> 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"
>>
>>
>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
>> news:Olfdy5kJHHA.1468@TK2MSFTNGP04.phx.gbl...
>>> 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
>>>
>>> "Bert" <bef***@gmail.com> schreef in bericht
>>> news:%237kvRVjJHHA.320@TK2MSFTNGP06.phx.gbl...
>>>> 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
>>>>
>>>
>>>
>>
>
>
Author
23 Dec 2006 9:27 PM
Spam Catcher
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in
news:Olfdy5kJHHA.1468@TK2MSFTNGP04.phx.gbl:

> 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.

Bookmark and Share