|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
regex expressionshi
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 "Bert" <bef***@gmail.com> wrote in news:#7kvRVjJHHA.320 @TK2MSFTNGP06.phx.gbl:> hi You can try this:> > > 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 (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 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 > 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 >> > > 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 >>> >> >> > 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 >>> >> >> > 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 >>>> >>> >>> >> > > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in RegEx is elegant and extendable - it's built for text parsing.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.
Other interesting topics
How I can find out on which platform I am running (32/64 bits)?
Why not use DAO? overriding array size How to determine if e-mail was sent OK Add Active Directory Users to a Group on a Workstation Windows Service to copy files to a Mapped Drive change date Autorun on USB Flash Drive FolderBrowserDialog questions How to select a network folder? |
|||||||||||||||||||||||