473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

simple egrep - regex question

To match "this" or "that" in string $str, I believe I would use this:

eregi("(this|that)", $str)

but what if I want to match "this" AND "that"?

I suppose I could use this:

eregi("this", $str) && eregi("that", $str)

But is there a better way?
Jul 17 '05 #1
6 3528
deko wrote:
To match "this" or "that" in string $str, I believe I would use this:

eregi("(this|that)", $str)

but what if I want to match "this" AND "that"?

I suppose I could use this:

eregi("this", $str) && eregi("that", $str)

But is there a better way?


eregi("this.*that|that.*this", $str)
JW

Jul 17 '05 #2
> > eregi("this", $str) && eregi("that", $str)

But is there a better way?


eregi("this.*that|that.*this", $str)


Is this saying: match the four letters "this" followed by a period, then
any combinbation of characters, then the four letters "that" (and vice
versa). What does the period do?
Jul 17 '05 #3
deko wrote:
eregi("this", $str) && eregi("that", $str)

But is there a better way?


eregi("this.*that|that.*this", $str)

Is this saying: match the four letters "this" followed by a period, then
any combinbation of characters, then the four letters "that" (and vice
versa). What does the period do?


The period stands for 'any character'. So .* stands for: zero or more of
any character.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #4
> >>>eregi("this", $str) && eregi("that", $str)

But is there a better way?

eregi("this.*that|that.*this", $str)

Is this saying: match the four letters "this" followed by a period, then any combinbation of characters, then the four letters "that" (and vice
versa). What does the period do?


The period stands for 'any character'. So .* stands for: zero or more of
any character.


I see. So, "this.*that" can be loosely understood to mean "match this and
that"?
Jul 17 '05 #5
deko wrote:
I see. So, "this.*that" can be loosely understood to mean "match
this and that"?


Yep: this anything-in-between-and that
JW

Jul 17 '05 #6
> > I see. So, "this.*that" can be loosely understood to mean "match
this and that"?


Yep: this anything-in-between-and that


10-4. Thanks for the help!
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Howard Dean | last post by:
I have a string with several carriage returns in it. For example: "This is my test string" I wish to convert it to "This is my test string" (remove all carriage returns. Can someone tell me...
2
by: K. Shier | last post by:
my regex for matching phone #'s: \({0,1}(?<areacode>{3})\){0,1}( |-){0,1}(?<prefix>{3})( |-){0,1}(?<suffix>{4}) which i then .Replace to become: (${areacode}) ${prefix}-${suffix} question: ...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
20
by: Larry Woods | last post by:
I'm drawing a blank... What is the regular expression for search a string for NO occurances of a substring? Example: I want to find all lines that do NOT have the substing "image" in them. ...
2
by: Theadmin77 | last post by:
Ok , i m playing with egrep command and i am a little stuck in these (i have researched google and MAN pages already ): 1.i need to search files using EGREP in the /var/log directory that contain...
4
by: bg_ie | last post by:
I have the following Regex - oldString = @"C:\ta"; Regex regexEndsInBackslash = new Regex(oldString + @"\\", RegexOptions.Singleline | RegexOptions.IgnoreCase); Any ideas why none of the...
4
by: MaxMax | last post by:
I want to add a text to another text using regular expressions... An example before= "foo" after= "foobar" before= "one" after= "onebar" before = "" after = "bar"
1
by: SSJVEGETA | last post by:
Hello, everybody. I have read some examples and manuals for the egrep command for Linux and I don't know if this egrep command is right for the particular files I am searching for. Here is what the...
2
by: Sin Jeong-hun | last post by:
I'm trying to replace \n with @(representing the actual new line character). Of course, \\n should not be replaced. What I'm trying to do is simply what the good-old printf does. For example, "\\n...
32
by: ndedhia1 | last post by:
Right now, I am using this line of code to get rid of data in a file called alarmNotification that I do not want: egrep "low debug.*\".*\"" $dbDir/alarmNotification.log but I am having some...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.