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.
3 4317
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.
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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".
...
|
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...
|
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...
|
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";...
|
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.
...
|
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:
...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |