473,445 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Regular Expression: how match a whole word?

Regular Expression: how match a whole word?

Hi All,
First of all, I’d express all my gratitude to all whom will help me about this topic.
I have a question about the Regular Expression Engine, the issue of mine is: Can I match an entire word using negative clauses?
In English: I’ve a simple text as: “man,men,mon,mun,car,cer,cir” and I’d match all the words which don’t contain in the first position the letter “m”, in the second “a” and in the third “n”. In this way:

Text: “man,men,mon,mun,car,cer,cir”
Word To Search: all the words which don’t contain the letters [m][a][n] in the co respective positions.
Pattern: “[^m][^a][^n]” (surely incorrect)

If I use as Pattern [m][a][n], I’m able to find the word “man”, but how I could the reverse process?
I’d like to retrieve all others words except this, is it possible?

Sorry, for this kind of simple question, I tried several times before creating this post, but all the searches of mine about this topic have been unsatisfied.
Oct 29 '10 #1
3 4317
Dormilich
8,658 Expert Mod 8TB
a very simple way of defining the RegEx just excludes the letter from the list: [a-ln-z][b-z][a-mo-z]. [^m][^a][^n] is not principally wrong, though it also matches non-letters.
Oct 29 '10 #2
Hi Dormilich,

first of all thank you for your reply!
You're right I mean I could remove all the letters I'd remove, but just for better understand the Regular Expression Engine: how I'd search using negative cluases?

In case I use a pattern like: [^m][^a][^n], instead of searching for all the words which don't contain the pattern "man", the engine searches for all the words which don't contain the letter "m: at the first position, the letter "a" at the second position and the letter "n" at the third one.
The result using the precedent text example (“man,men,mon,mun,car,cer,cir” ) will be "an,en,on,un,ar,cer,ci".

I’d like to retrieve all others words except this, is it possible?
Oct 30 '10 #3
Dormilich
8,658 Expert Mod 8TB
The result using the precedent text example (“man,men,mon,mun,car,cer,cir” ) will be "an,en,on,un,ar,cer,ci".
no. given you use /[^m][^a][^n]/g on this string, you get: "an,", "en,", "on,", "un,", "ar,", "cer", ",ci". what you request is a 3 character match, thus your result is a couple of matching 3 characters strings.
Nov 1 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Derek Stone | last post by:
In my continuing inability to completely understand regular expressions I have a new one for you. I'd like to capture a string "A" unless it is anywhere in between string "B" and string "C". ...
4
by: Johnny Lee | last post by:
Hi, I've met a problem in match a regular expression in python. Hope any of you could help me. Here are the details: I have many tags like this: xxx<a href="http://xxx.xxx.xxx" xxx>xxx xxx<a...
2
by: malauddin | last post by:
Hi all, I am looking for a regular expression to find a word at the beginning of a line and then read the entire line. From the example below, I want to find the word "FN" and then read entire...
17
by: Randy Webb | last post by:
I know that the /g flag will match all occurrences. Is there a way, with a Regular Expression, to match all occurrences *except* the last one? pattern = /df/g; var myString = "asdfasdfasdfasdf";...
2
by: teo | last post by:
match word with interpunctuation Hallo, I need to build a regular expression able to match a specified word, preceded and followed by few chars (mainly interpunctuation) Below the code. ...
2
by: teo | last post by:
I have a problem (partial). Some days ago I asked for a way to extract a word and few text around it (30 chars on the left and 30 on the right) from a long text. I went good with: ...
5
by: MrNobody | last post by:
is there a simple way to make it so your regex only matches whole words? i was thinking simply something like: *match_string* but then I think it would fail if the word was at the beginning...
8
by: Summercool | last post by:
somebody who is a regular expression guru... how do you negate a word and grep for all words that is tire but not snow tire or
5
by: Peng Yu | last post by:
Hi, The following code snippet is from /usr/bin/rpl. I would like the it to match a word, for example, "abc" in ":abc:". But the current one would not match "abc" in ":abc:". I tried to modify...
6
Markus
by: Markus | last post by:
I'm asking the question for once! Say I have the expression @@ that matches anything other than the characters specified. I also want spaces to be allows, including \n, \t, etc. I've tried adding...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.