473,398 Members | 2,393 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,398 software developers and data experts.

Regular expression to compare two variables similar to SQL: field LIKE 'value%'

I am trying to compare two variable but using regular expression:

$access = "glasgow"

$areaid = "glasgow-westend-byers_rd"

using the two variables, I would like the areaid variable to be
compared with the access variable. the regular expression function will
return true if $access matches the start of $areaid. So the two above
would return true

The following would also return true:

$access = "glasgow-westend"

$areaid = "glasgow-westend-byers_rd"

or

$areaid = "glasgow-westend-greatwestern_rd"

However, the following should return false though:

$access = "glasgow"

$areaid = "stirling-glasgow_rd"

Although the value for $access, 'glasgow', appears in the $areaid it
does not appear at the start.
If I were to do this in SQL it would be something like:

$select = "SELECT * FROM areas WHERE areaid LIKE '" . $access . '%"

Note the use of '%' at the end of the compare LIKE field

Unfortunetely I have never been able to properly get my head round
regular expressions.

Any help?

Cheers, burnsy

Oct 18 '05 #1
2 3129
bi******@yahoo.co.uk wrote:
I am trying to compare two variable but using regular expression:

$access = "glasgow"

$areaid = "glasgow-westend-byers_rd"

using the two variables, I would like the areaid variable to be
compared with the access variable. the regular expression function will
return true if $access matches the start of $areaid. So the two above
would return true


if (ereg("^$access", $areaid)) {
// ... do something
}

Cheers,
Andy
Oct 18 '05 #2
bissatch wrote:
$areaid = "glasgow-westend-byers_rd"


on a sidenote, bissatch, the street between Dumbarton Road and Great
Western Road spells its name with an 're', does it not? it runs through
what was once called the Byres of Partick ('byre' = shed for keeping
cattle in). which begs the question, is there more heifers there now (on
a Friday night) than there was then?

--
Jock
Oct 21 '05 #3

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

Similar topics

6
by: Chris Lasher | last post by:
Hello, I would like to create a set of very similar regular expression. In my initial thought, I'd hoped to create a regular expression with a variable inside of it that I could simply pass a...
1
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...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
7
by: Tizzah | last post by:
What is wrong with that? regex = /^(http|https):\/\/+({1}+)*\.{2,5}(({1,5})?\/.*)?$/ if(field.hpage.value != regex.test(field.hpage.value)){ alert("Bad Homepage") field.hpage.focus()...
25
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...
11
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...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
10
by: Thomas Dybdahl Ahle | last post by:
Hi, I'm writing a program with a large data stream to which modules can connect using regular expressions. Now I'd like to not have to test all expressions every time I get a line, as most of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.