473,382 Members | 1,313 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,382 software developers and data experts.

PREG matching

I'm trying to match:
<image=1,right>
- or -
<image=1>

where the 1 and 'right' become parameters.

So far I have:
preg_match_all('#<image=(.+?),(.+?)> | <image=([^>]+)#msi', $body,
$image_tags);

and

$image_count = preg_match_all('#<image=([^>]+)#msi', $body, $image_tags);

I'm trying to see if I can get them both into the one regexep, I assume
I have to use an alternative | somewhere, just not sure where.

Can anyone help?
Jul 17 '05 #1
4 1651
Logical wrote:
I'm trying to match:
<image=1,right>
- or -
<image=1>

where the 1 and 'right' become parameters.

So far I have:
preg_match_all('#<image=(.+?),(.+?)> | <image=([^>]+)#msi', $body,
$image_tags);

and

$image_count = preg_match_all('#<image=([^>]+)#msi', $body, $image_tags);

I'm trying to see if I can get them both into the one regexep, I assume
I have to use an alternative | somewhere, just not sure where.

Can anyone help?


Of course I had to make a mistake in pasting my code.

That should have read:
preg_match_all('#<image=(.+?),(.+?)>#msi', $body, $image_tags);
and
preg_match_all('#<image=([^>]+)#msi', $body, $image_tags);
Jul 17 '05 #2
.oO(Logical)
That should have read:
preg_match_all('#<image=(.+?),(.+?)>#msi', $body, $image_tags);
and
preg_match_all('#<image=([^>]+)#msi', $body, $image_tags);


Try (untested)

preg_match_all('#<image=(.+)(,(.+))?>#isU', $body, $image_tags);

Micha
Jul 17 '05 #3
"Logical" <me@privacy.net> wrote in message
news:41***********************@un-2park-reader-01.sydney.pipenetworks.com.au...
I'm trying to match:
<image=1,right>
- or -
<image=1>

where the 1 and 'right' become parameters.

So far I have:
preg_match_all('#<image=(.+?),(.+?)> | <image=([^>]+)#msi', $body,
$image_tags);

and

$image_count = preg_match_all('#<image=([^>]+)#msi', $body, $image_tags);

I'm trying to see if I can get them both into the one regexep, I assume
I have to use an alternative | somewhere, just not sure where.

Can anyone help?


I could be wrong, but wouldn't it be easier (or anyways take less processing
time) to do a str_replace()? Ex:

<?php
$params=explode( "|",
str_replace(
array( "<image=", ",", ">" ), array( "", "|", "" ), $body
)
);

print_r($params);
?>

- JP
Jul 17 '05 #4
"kingofkolt" <je**********@comcast.net> wrote in message
news:QL0%c.142335$mD.61186@attbi_s02...
"Logical" <me@privacy.net> wrote in message
news:41***********************@un-2park-reader-01.sydney.pipenetworks.com.au...
I'm trying to match:
<image=1,right>
- or -
<image=1>

where the 1 and 'right' become parameters.

So far I have:
preg_match_all('#<image=(.+?),(.+?)> | <image=([^>]+)#msi', $body,
$image_tags);

and

$image_count = preg_match_all('#<image=([^>]+)#msi', $body, $image_tags);
I'm trying to see if I can get them both into the one regexep, I assume
I have to use an alternative | somewhere, just not sure where.

Can anyone help?


I could be wrong, but wouldn't it be easier (or anyways take less

processing time) to do a str_replace()? Ex:

<?php
$params=explode( "|",
str_replace(
array( "<image=", ",", ">" ), array( "", "|", "" ), $body
)
);

print_r($params);
?>

- JP


My mistake. That logic would require that $body contains only the line
<image=1,right> and nothing else before or after the tag. Please ignore
me...

- JP
Jul 17 '05 #5

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

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
4
by: Margaret MacDonald | last post by:
I'm trying to write a filter that will ignore text of the form '\_foo\_' while filtering text of the form '_foo_'. In other words, a backslash is meant to protect against the operation of this...
2
by: Juggernaut | last post by:
Hi I was trying to write a script to replace some text inside some tags. Lets say I had <tag stuff=stuff><tag stuff=otherstuff><another> I wanted it to find all the <tag and remove them. So...
2
by: toedipper | last post by:
Hello, The following bit of code does a preg match and does something if true (sets $browser to ppcie) Without using if then and else's how do I code it so it does not equal what it is...
4
by: system7designs | last post by:
I don't know preg's that well, can anyone tell me how to write a regular expression that will select everything BUT files/folders that begin with ._ or __?(that's period-underscore and underscore...
14
by: frizzle | last post by:
Hi group, I have a function which validates a string using preg match. A part looks like if( !preg_match( '/^(+((*)?)?)$/', $string ) || preg_match( '/(--|__)+/' ,$string) ) { i wonder...
1
by: terence.parker | last post by:
I am trying to do a search through some data, more specifically HTML, to extract data from it. So for example I may have: <b>Title:</b<em>This is a title</em> <b>Name:</b<em>Fred</em> I wish...
5
by: monomaniac21 | last post by:
hi all what is the preg for capitals in a word to be replaced by that word preceded by a space? i need to be able to do this in preg: thisWord := this Word AnotherExample := Another Example
3
moishy
by: moishy | last post by:
If I wanted to match for instance, all characters that are not in <TAGS>, I would search for all ">ANYTHING<". But how do I make that "ANYTHING"? What will be the PREG for absolutely ANY...
2
by: JanDoggen | last post by:
function vldLicense($lic) { echo "called with lic: ". $lic . "<br>"; echo preg_match('', $lic) . "<br>"; if (preg_match('{4}-{4}-{4}-{4}', $lic) == 0) return false; return true; } gives me:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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:
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 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.