Hi,
A quick regex question which I've worked around for the time being,
but would like an answer to if anyone can help.
I want to match on all strings which end _id, but not those ending
row_id.
Some sample strings:
row_id
parent_id
person_id
person
I'd like to match all but the 1st and last.
I've tried many variants, including
preg_match('/(row)\w{0}_id$/',$subject);
preg_match('/(row){0}_id$/',$subject);
preg_match('/(?!row)_id$/',$subject);
None work correctly. As I say I've worked around this issue as I have
very little time, but would like to know the proper solution.
Thanks in advance. Greg. 4 5249
..oO(gf****@gma il.com)
>I want to match on all strings which end _id, but not those ending row_id.
Some sample strings:
row_id parent_id person_id person
I'd like to match all but the 1st and last.
I've tried many variants, including
preg_match('/(row)\w{0}_id$/',$subject); preg_match('/(row){0}_id$/',$subject); preg_match('/(?!row)_id$/',$subject);
The last one was very close:
preg_match('/(?<!row)_id$/', $subject);
Notice the '<' to make it a negative look-behind assertion instead of
negative look-ahead.
Micha
<gf****@gmail.c omkirjoitti
viestissä:11*** *************** ****@q2g2000cwa .googlegroups.c om...
Hi,
A quick regex question which I've worked around for the time being,
but would like an answer to if anyone can help.
I want to match on all strings which end _id, but not those ending
row_id.
Some sample strings:
row_id
parent_id
person_id
person
Somebody answered from the regex point of view, which is not my expertise,
but i ask: do you really need regex to do this, especially if you feel they
are difficult? Can you just applie string finding functions? End is "_id"
but end is not " row_id", that makes two conditions, or do i miss something?
On Feb 6, 2:50 pm, "P Pulkkinen"
<snip>
Somebody answered from the regex point of view, which is not my expertise,
but i ask: do you really need regex to do this, especially if you feel they
are difficult? Can you just applie string finding functions? End is "_id"
but end is not " row_id", that makes two conditions, or do i miss something?
Hi, sorry for not getting back to the thread earlier. Yes indeed this
could be done with two conditions on a string match.
It was simply the regex challenge! I have a perl project coming up
really soon in which I think I'll be needing to do a lot of regex
work, so just wanted to get some practice in.
Thanks for the replies everyone!
On Feb 6, 1:46 pm, Michael Fesser <neti...@gmx.de wrote:
.oO(gfr...@gmai l.com)
I want to match on all strings which end _id, but not those ending
row_id.
Some sample strings:
row_id
parent_id
person_id
person
I'd like to match all but the 1st and last.
I've tried many variants, including
preg_match('/(row)\w{0}_id$/',$subject);
preg_match('/(row){0}_id$/',$subject);
preg_match('/(?!row)_id$/',$subject);
The last one was very close:
preg_match('/(?<!row)_id$/', $subject);
Notice the '<' to make it a negative look-behind assertion instead of
negative look-ahead.
Micha
That did the trick, thanks Micha! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kenneth McDonald |
last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate
feedback, suggestions, and criticism as I work towards finalizing the
API and feature sets. rex is a module intended to make regular expressions
easier to create and use (and in my experience as a regular expression
user, it makes them MUCH easier to create and use.)
I'm still working on formal documentation, and in any case, such
documentation isn't necessarily the...
|
by: Ward Cleaver |
last post by:
Hi. I have an assignment to do some validating of a form using
javascript and mostly the search() method. I'm having problems
getting a positive validation for phone numbers like "123-456-7890"
and "123.456.7890" but not like "123.456-7890". The regular
expression I'm using now is something like this:
ok = pn.search(/(^\d{3}-\d{3}-\d{4}$)|(^\d{3}.\d{3}.\d{4}$)/);
Which to me looks like it SHOULD do what I want it to and not come
back...
|
by: Tom Deco |
last post by:
Hi,
I'm trying to use a regular expression to match a string containing a #
(basically i'm looking for #include ...)
I don't seem to manage to write a regular expression that matches this.
My (probably to naive) approach is: p = re.compile(r'\b#include\b)
I also tried p = re.compile(r'\b\#include\b) in a futile attempt to use
a backslash as escape character before the #
|
by: Dimitris Georgakopuolos |
last post by:
Hello,
I have a text file that I load up to a string. The text includes
certain expression like {firstName} or {userName} that I want to match
and then replace with a new expression. However, I want to use the
text included within the brackets to do a lookup so that I can replace
the expression with the new text.
For example:
|
by: Billa |
last post by:
Hi,
I am replaceing a big string using different regular expressions (see
some example at the end of the message). The problem is whenever I
apply a "replace" it makes a new copy of string and I want to avoid
that. My question here is if there is a way to pass either a memory
stream or array of "find", "replace" expressions or any other way to
avoid multiple copies of a string.
Any help will be highly appreciated
| |
by: Cylix |
last post by:
I am going to write a function that the search engine done.
in search engine, we may using double quotation to specify a pharse
like "I love you",
How can I using regular expression to sperate each pharse?
test case:
"I love" all "of you"
I would like it return:
|
by: Mike |
last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in
matches. I would like to get what the actual regular expression is.
In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION
DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH
CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How
do I gain access to the expression (not the matches) at runtime?
Thanks,
Mike
|
by: Steve |
last post by:
Hi All,
I'm having a tough time converting the following regex.compile patterns
into the new re.compile format. There is also a differences in the
regsub.sub() vs. re.sub()
Could anyone lend a hand?
import regsub
|
by: jayanthigk2004 |
last post by:
Input
a-
Patterns
\w*-*
\w*(-*)
\w*(-)*
\w**
|
by: NvrBst |
last post by:
I want to use the .replace() method with the regular expression /^ %VAR
% =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)"
regular expression with "":
---------------------------------
myStringVar = myStringVar.replace("^" + iName + "=,($|&)", "");
---------------------------------
The following DOES replace it though:
---------------------------------
var match = myStringVar.match("^" + iName + "=,($|&)");
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |