Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP






SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





How Do I Get This Value From A Regular Expression


I'm having trouble with preg_match. I want to get the value in
parenthese from this pattern

$pattern = "/ab(.*)cde/";
$str = "abxyzcde";

What preg_match expression would i have to write to get the value "xyz"
into a string?

I'm using php 4.4.4.




View Complete Forum Thread with Replies
Sponsored Links:

Related Messages:
Need Help With A Regular Expression
I need to replace all quotes with an arbitrary character - but only if they are between tags:

<span class="large">big text</span>

This would become something like:

<span class=QlargeQ>big text</span>

I've been trying lots of permutations of this, without success:

$txt = preg_replace("/<(.*?)("){1,}(.*?)>/", "<1Q3>", $txt);

View Replies !   View Related
Regular Expression To Get Rid Of <br>
I've got a tag(let's call it [tag]) that has several <br>s in front of it. I want to get rid of the <br>s.

The problem here is that there are an unknown amount of <br>s before the tag, and an unknown amount of spaces in between seemingly random placements of <br>s. Here is an example, to clarify.

$str = "<br> <br><br><br> <br><br> <br> <br> [tag]";

I just randomly wrote this, so this isn't real, but it's similar to my situation. The regular expression I wrote to get rid of one <br> was...

$pattern = "<br>[tag]";

then the replacement would be....

$replacement = "[tag]";

View Replies !   View Related
Regular Expression Q
I have an HTML file and want to convert all tags to lowercase, but
leave the attributes alone. For instance:

<SOME TAG ATTRIBUTE="Text THAT may be Upper"></SOME TAG>

Needs to be converted to:

<some tag attribute="Text THAT may be Upper"></some tag>

I can easily convert everything in the tag to lower using '<.*?>' but am
stuck getting PHP to ignore whatever is in quotes.

View Replies !   View Related
Value From A URL Using Regular Expression
We have a URL than can be any one of the following

http://mydomain.com/CA/
http://mydomain.com/123CA/
http://mydomain.com/123CA456/
http://mydomain.com/123CA456/index.htm

In need a little help with the regular expression that would extract the value after the domain name. We want $myvalue to be equal to the part of the URL just after the domain name, but not including anything after the subsequent slash"/". for example,
http://mydomain.com/123CA456/index.htm
should save as: $myvalue = 123CA456 any ideas of the regular expression we could use?

View Replies !   View Related
Regular Expression In PHP
How can I get all the values which are between Name tags as follows:

<emp>
<name>N1</name>
<age>1</age>

<name>N2</name>
<age>2</age>

<name>N3</name>
<age>3</age>

<name>N4</name>
<age>4</age>

</emp>

View Replies !   View Related
Regular Expression -
can anyone translate this into plain english?

preg_match_all("/(w+[,. ?])+/U", $text, $words);

View Replies !   View Related
Regular Expression [Help]
I must find a regular expression to find every declaration af a
variable in a php programm.....

I tried:

/$([a-zA-0-9_])*(s|S)=(s|S)/is

But it doesn't reall go :-(

I've got no expreience in things like regular expressions...

And: Is it possible to look if the decaration ist in ' or " ? If eyes:
how and if no :-@

View Replies !   View Related
Regular Expression Help
I am using the preg_match function (in PHP) that uses perl regular
expressions. Apparently I don't really understand regular expressions
though.

If this is the regular expression

/^s*(d+.d+)|(.d+)|(d+)s*$/

How does this:

40:26:46.302N 79:56:55.903W

match? I thought when I added the ^ and $ that meant it had to match
the whole thing? It seems to only be matching .302

View Replies !   View Related
Using Regular Expression
I am using regular expression. But I have some problems with it, look at the following code:

Code:
<HTML>
<HEAD><TITLE>Finding substring</TITLE></HEAD>
<BODY>
<?PHP
$input = "maths 89 c++ 92 java 85 uml 80";
ereg("[0-9]*",$input,$regs);

echo "Scores:<br>";
echo "num: " . count($regs);
for($i=0;$i<count($regs);$i++){
echo "$regs[$i] ";
}
?>
</BODY>
</HTML>

View Replies !   View Related
A Regular Expression
Is there a way to do a greater than and less than in a regular expression? I am looking to list only images that are less than 10 in there name.

pan1.jpg
pan2.jpg
pan3.jpg
pan4.jpg ... up to pan10.jpg

I was able to get it to just list pan1.jpg to pan9.jpg using the following expression, (pan[^[1-9]$]).jpg. I need it to include the 10 as well. I like to know if less than and greater than are available.

View Replies !   View Related
Need Regular Expression For Max(x1, X2, ..)
i need a regexp to test strings like "max(x, y)", "max(x, y, z)". In other words, i have to check the correctens of the php-function max().

How can i do this?

View Replies !   View Related
Regular Expression :: [^a-zA-Z0-9@._]
I have been looking around at several tutorials about building a custom simple CMS. I found one simple enough that I thought I could use this to build my own upon, I wanted to start adding as much security I can to it but I'm lacking in knowledge. I thought the first steps I would take would be to place all of my includes above root directory, and now I'm thinking of adding a regular expression to filter the data entered from my form.

I'm a little-bit lost. I was thinking maybe something like: [^a-zA-Z0-9@._] what I think this regular expression is doing is, matching anything other than the ranges and extra characters I listed. So I'm guessing I would use an if statement with that regular expression, saying if anything other than these characters are found, do not send the query, else send it.

View Replies !   View Related
Regular Expression Get All Between <td>
<td valign=top style="width:30em">
----------------------
more lines with text and html tags (no </td>)
----------------------
</td> <!-- first occurence -->

i tried
"/<td valign=top style="width:30em">
(.)*</td>/"

View Replies !   View Related
Regular Expression
<?php

$string = "This is a test";
echo str_replace(" is", " was", $string);
echo ereg_replace("( )is", "1was", $string);
echo ereg_replace("(( )is)", "2was", $string);

?>

output is like:This was a testThis was a testThis was a test.

View Replies !   View Related
Getting Variables Out Of A Regular Expression
If i need to do some big time parsing, and I need what I'm parsing out to go into nice little varaibles, how do I do that without a million ugly preg_split functions?

Say I have this line:

"blah blah blah ~~ [THIS] -- blah blah -- [THAT]"

How could I end up with $this and $that, containing "[THIS]" and "[THAT]" respectively,
possibly in only a few lines of code?

View Replies !   View Related
Regular Expression Problem
The problem: I have an html page I want to parse. before I parse it, I want to remove everything in HTML comments <!-- -->,My code:

View Replies !   View Related
Regular Expression Function
How do I find a pattern in a string, and simply return the text that matched the pattern?

View Replies !   View Related
Regular Expression (domain)
Hi, I am trying to validate a valid second level domain with this complicated stuff. Thus what I have here is : PHP Code:

View Replies !   View Related
Quick Regular Expression
I have a string and I need to check and see if there is an # sign in it. Is there a regular expression that will do that for me?

View Replies !   View Related
Regular Expression Negation
I'm trying to negate a phrase rather than just a single character in a regular expression. Is there a syntax for multiple character negation? For example, if 'Brenda Brown' and 'Brenda Jones' are OK, but not 'Brenda Smith'?
Regex is such a powerful tool -surely there's a multiple negation operator.

View Replies !   View Related
Basic Regular Expression
I need to check a string to make sure it only has letters, and/or numbers and/or an underscore in it.

View Replies !   View Related
Regular Expression Help Please (hopefully Simple)
I've got a file with this in it: [Event "Some string data"]

The data I'd like extracted is within the quotes: Some string data

I can read the file out and extract (using string positions) the data I'd
like but it would neater if I use a regular expression. Only problem is I've
never seen a working example of this type of extraction and am completely
new to PHP.

View Replies !   View Related
Problem With A Regular Expression
I'm having a regular expression problem. I need it to match all occurences of "href="(not http)<whatever-else"". My attemps have been:

href="[^h][^t][^t][^p][^:][^/][^/][^"]+", which works, but will fail on things like "href="attribute.html"", as there are t's where the regex doesn't expect them. Thus, this attempt can be ditched.

href="(^http://)["]+", which doesn't work, and ends up matching only things like "href="httpandthensomemore.html""

and I couldn't really figure out more. I need a regular expression that only matches the WORD http, not each individual character, and I need it to match the whole word, as this is not used as a check for links starting with http, but for replacing relative links with absolute ones in the following piece of PHP code:

preg_replace("/href="<regex that works... hopefully>"/", "http://address.com/$1", $pieceOfHTML);

And I chose to post this here and not in the PHP section, as it's not concerning the PHP but the regular expression....

View Replies !   View Related
Regular Expression L & U Switches
In the following regular expression:

$_="BCADeFGHIJKL";
if (/L[w]E/) { print "true"} else { print "false" };
if (/U[w]E/) { print "true"} else { print "false" };

why the first one print true while the second one print false?

Can someone explain L U?

View Replies !   View Related
Regular Expression Pattern
I'm having trouble with a regular expression pattern. I want to match "c" or "k" or "ck" but not "ch". It's that last bit that's giving me trouble. Example:

Match "sic"
or "sik"
or "sick"
or "sikc"
not "sich"

Here's the pattern that I'm using so far:
/(^|[^a-zA-Z])(s+|$+|&+)(W|( )|(<.*> )|s|_)*(a+|e+|i+|o+|u+|*+|&+|^+|%+|$+|#+|@+|!+)(W|( )|(<.*> )|s|_)*(c+|k+|((c+)(W|( )|(<.*> )|s|_)*(k+))|((k+)(W|( )|(<.*> )|s|_)*(c+)))([^a-zA-Z]|$)/gi

View Replies !   View Related
Preg_match_all // Regular Expression
right now the script just browse through the url, and returns all the links in the page, but what i would like to try, is to make it return the links AND the text between the <a href and </a>, so if a link says PHP Code:

View Replies !   View Related
Regular Expression Troubles
I'm not the most competent person when it comes to regular expressions. Needless to say, i attempted my own pattern and have manage to balls something up cronic The following is the pattern that i wish to convert: PHP Code:

View Replies !   View Related
How To Refine My Regular Expression?
What I want to do is replace all instances of $searchterm in $text with the string "^^^^^", but only if $searchterm is within an HTML tag.

For example, if $text is "<pre>Hello!</pre>", and $searchterm is "pre", I want the result to be: "<^^^^^>Hello!</^^^^^>".

Here's what I have now:
$text = preg_replace ( "/(<.*?)($searchterm)(.*?> )/", "1^^^^^3", $text );

Unfortunately, this doesn't work. For example, if $text is "<b>pre</b>" and $searchterm is "pre", the pre gets replaced. Why? Because while the "pre" may not be in an HTML tag, technically it's still between brackets - the first and last characters of $text.

View Replies !   View Related
Why Does This Regular Expression Fail?
Suppose I have these five lines in a file somewhere:

<p>This entry should belong to:
<select name="formInputs[id_of_neighborhood_to_which_this_belongs]">
<option value="">(No choice made)</option>
<?php getDatabaseTableValuesInOptionTags("neighborhoods", "id",
"state"); ?>
</select>

Suppose I open this file and read the contents into a string called
$string. Suppose I then give the string to this function:


function matchAllPhpFunctionsInString($subject=false) {
// 11-08-06 - this is being called in importForm

$pattern = "<";
$pattern .= "?php.*(.*); ?";
$pattern .= ">";
$pattern = "/$pattern/";
preg_match_all($pattern, $subject, $matches);
// print_r($matches);

// 09-19-06 - there is no point returning a 2 dimensional array, so we
will make
// it one dimensional.
$arrayOfPhpFunctionNames = $matches[0];
return $arrayOfPhpFunctionNames;
}

This function is suppose to find the PHP command. It works on other
pages, but not the one I've posted above. Why is that? Why would this
regular expression not find this PHP command?

View Replies !   View Related
Selecting With Php (regular Expression?)
first a user can pick a name ($name) and gender ($gender; value is "m" or "f"). in mysql, i'm going to have a whole blob of text. here's a short example:

[[name]] said {he|she} was going to the store today.

i can change [[name]] to $name but is there a way i can use "he" when $gender is "m' and "she" when $gender is "f"? i'm guessing with regular expression? and in the braces may contain longer things that may contain spaces, etc. like:

{hansome guy|cute girl} i'm not too good with regular expression, could someone come up with one that might work?

View Replies !   View Related
Finding XML With Regular Expression
I am trying to extract the XML out of a string with a regular expression and I am going crazy trying to figure it out. Here is the text String Code:

View Replies !   View Related
Query In Regular Expression
what does the flwg rule mean in regular expression:

([^#].*)

View Replies !   View Related
Regular Expression In A Form
I have used some of this code from the PHP manual, but I am bloody hopeless
with regular expressions. Was hoping somebody could offer a hand.

The output of this will put the name of a form field beside name.
I want to get the following but not sure how to modify the code below.

1. Field Name (to appear beside NAME:)
2. Field Type (to appear beside TYPE:)
3. Field Value (to appear beside VALUE:)

Make sense.
It is part way there, just need some help finishing it.

$filename = "form-eg.php"; // Open file to read HTML with Form code
$fd = fopen ($filename, "rb");
$contents = fread ($fd, filesize ($filename));
preg_match_all ('/<input.*?names*=s*"?([^s>"]*)/i', $contents,
$matches); // get all input fields and attributes and values

for ($i=0; $i< count($matches[0]); $i++) {
echo "matched: ".$matches[0][$i]."<br />";
echo "NAME: ".$matches[1][$i]."<br />";
echo "TYPE: ".$matches[3][$i]."<br />";
echo "VALUE: ".$matches[4][$i]."<br />";
}

fclose ($fd);

I will also need to run another check for:

View Replies !   View Related
Regular Expression Inquiry
I'm processing the following sequence with length more than 100k

1 cagatgctga taaaaaagtg tgttcctcat agcatttatt taattgaaat atttcaagaa
61 cttgaatgta ctaaaaattg agacaaacag tagcaaatca taaaaaaaaa ttgaagtgaa
121 ttttacaact ggattcatgt gcctaatatt ttcattggga agtggattca tgtttaacat
181 ttccattggg <snippet>

i wrote a program

<?php
session_start();

if (isset ($_POST['seq']) )
$seq = $_POST['seq'];
else
$seq= $_GET['seq'];

$seq = preg_replace("/[s
0-9]/", "", $seq);
echo $seq;

?>

but it generates an output of fragmented sequences (i.e. partially processed
result), what is the problem?

View Replies !   View Related
Regular Expression (preg_replace)?
How can I write the thing below as a regular expression (preg_replace)?

$array = array("-0", "-1", "-2", "-3", "-4");
$key = str_replace($array, "", $key);

I am trying to learn regular expressions, but I find them hard and this
seems like a really simple place to start....

View Replies !   View Related
Regular Expression : {link}
text with {link:pagehref}a link{/link}.

replace to ->

text with <a href="pagehref">a link</a>

I tried several things but nothing seems to work... e.g.

$value=preg_replace("/{link:(.+?)}(.+?){/link}/s","<a href="$1"
target="_blank">$2</a>",$value);

View Replies !   View Related
Regular Expression Syntax
I was working on a regular espression working from an example. I wrote out my version basically the same thing except minus the /A at the beginning and the / at the end. (see below) My version blow errors. So my question is what does /A and / do? PHP Code:

View Replies !   View Related
Regular Expression Books
what good book would you guys recommend on using regular expressions in PHP?

View Replies !   View Related
Help Needed With A Regular Expression...
I'm creating a mini CMS that will store content in a MySQL
database. What I am trying to do is parse the content and replace
certain keywords with a link. The keywords and associated links are
kept in a MySQL table.

Here is an example.

$keyword = "Widgets Technology Co.";
$location = "http://www.widgets.com/about";

$keyword2 = "Widgets";
$location2 = "http://www.widgets.com";

$content = "We have the best Widgets at Widgets Technology Co.";

I want to parse through $content looking for $keyword and replacing it
with:
<a href="$location">$keyword</a> (this I can do with no problem)

but I am going to be looping through a series of keywords (phrases)
sorted by length (longest to shortest) that may or may not contain
other keywords such as the values above for $keyword2 which would
cause nested links and other nonsense.

so what I'm needing is a regular expression that will find the
$keyword (phrase) that is not already between "<a href =" and "</a>"
so that it will not try to relink it.

so far, this is the regular expression that I have, but does not work
properly:

[^(^<a href=)][^(>)]($keyword)[^(a>)$]

View Replies !   View Related
Username Regular Expression
Does anyone have a good regular expression snippet to validate usernames
and passwords?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.

View Replies !   View Related
Regular Expression, (preg_split Etc...), Some Help Please.
Consider the string

&#391;,2,3', I can split it using, preg_split("/,/", &#391;,2,3') and i correctly
get [0]=1, [1]=2,[2]=3.

Now if i have

&#391;,"2,3"' i could split it using preg_split("/(?<!"),/d", &#391;,"2,3"') and i
correctly get [0]=1, [1]="2,3".

But it clearly does not work in some more advanced cases, for example

&#391;," 2 , 3"' or &#391;,"2 , 3 "' mainly because the /d is no longer useful.

So how can i search for a regular expression that is *not within*
apostrophes?

I think i might have to write my own split function especially if i have an
extreme case like, &#391;," 2 , " 3"', (note the escape apostrophe).

View Replies !   View Related
Email Regular Expression
Someone posted this on a message board and some people responded that it was good and others said it might have problems. So I thought I would come to the experts here and get a second opinion.

!eregi( "^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email ) )

Any thoughts?

View Replies !   View Related
Regular Expression Error
I want to use headers to redirect the client if they didn't come from the
correct page, but I have a problem with one page. If they leave a form field
empty, they are redirected back to the page they came from with an error
number and a 6 digit 1d number in the location bar which defines what field
was left empty( order.php?prob=2&id=000001)

My only problem is that when they repost, the $_SERVER['HTTP_REFERER']
contains the get variables and doesn't match, so they get redirected.
Instead of coding an if statement for every possible combination of error
numbers and ids, I decided it would be faster to use regular expressions.
This is the first time I've ever used regular expressions. I've found lots
of tutorials for regular expressions in Perl, but none of them seem to cross
over properly to PHP, or at least for what i need. I have the following
code....

preg_match("http://fakeaddress.sytes.net/pillowtalk/order.php(?prob=[0-4
])?", $_SERVER['HTTP_REFERER'])

which keeps on returning "Warning: Delimiter must not be alphanumeric or
backslash in line 2"
I was wondering if anybody knows of a good place to learn how to use regular
expressions in PHP, or if you could tell me what I'm doing wrong?

View Replies !   View Related
Have Any Idea About Regular Expression ?
Have any idea about regular expression ?

I posted this question to other newsgroup, but I'm still hungry for it.

I tried to change any numeric characters to Zero like following;
$aaa = ereg_replace ("|0-9|", "0", $sentence);
This seems working perfect.

My question is how I can do this function only for outside of html tags.
I don't want any numeric characters to be changed inside html tags.

View Replies !   View Related
A Regular Expression Inquiry
for an array element $fields[$j] containing:

gb:AF367205.1 DB_XREF=gi:17225988 TID=Os.1005.1 CNT=36 FEA=FLmRNA
TIER=FL+Stack STK=9 UG=Os.1005 DEF=Oryza sativa 1-deoxy-D-xylulose
5-phosphate reductoisomerase precursor, mRNA, complete cds; nuclear gene for
plastid product. PROD=1-deoxy-D-xylulose 5-phosphate
reductoisomeraseprecursor FL=gb:AK059692.1 gb:AK099702.1 gb:AF367205.1
REP_ORG=O. sativa

i try to extract useful content by:

if (preg_match("/PROD=(.+)s{2}/", $fields[$j], $match ) )
$fields[$j] = $match[1];
else if (preg_match("/UG_TITLE=(.+)s{2}/", $fields[$j], $match ) )
$fields[$j] = $match[1];
else if (preg_match("/DEF=(.+)s{2}/", $fields[$j], $match ) )
$fields[$j] = $match[1];

i have confirmed it is 2 spaces (i.e. not tab, linefeed, new line). i just
don't know why sometimes it gives me:

PROD=1-deoxy-D-xylulose 5-phosphate reductoisomeraseprecursor
FL=gb:AK059692.1 gb:AK099702.1 gb:AF367205.1

or more (i.e. run-on matching). i don't know if it deals anything with
matching as much as possible. i also tried:

"/DEF=(.+)s{2}[A-Z].*/" but it still doesn't work. BTW, because i know
sometimes what i want is at the end, so i also use "/DEF=(.+)$|s{2}/" but
it also doesn't work.

View Replies !   View Related
Getting <img> Alt Text With Regular Expression
Here is what I have:

$regexp = "<imgs[^>]*alt=("??)([^" >]*?)1[^>]*>";
if(preg_match_all("/$regexp/siU", $input, $img, PREG_SET_ORDER)) {
foreach($img as $alt){
echo "$alt[2] <br />";
}}

I am a reg expression noob. This presents empty results. Can anyone find the error?

View Replies !   View Related
Regular Expression, Letters Only
I've been trying to create a regex that says a string must be letters only the combinations that I thought would work, don't:

preg_match("/[a-zA-Z]/", $string)

or

preg_match("/w/", $string)

but it will match "string" or "string#" or "string@!" as long as there are letters in the string my regex will match it. But I only want it to match if there are only letters.

View Replies !   View Related
Regular Expression Conditionals
I have a fairly complex regular expression that has two captures. One of the captures is simply "([^a-z]+?)" because I need only capitalized letters or non-alphanumeric symbols or spaces and the other is "(.+?)" because it could be anything. However, I need both of these to contain more substance than nothing but spaces.

So if either captures only a long block of spaces how would I detect that within the regular expression so that the expression fails and starts work on the next match? I am trying to avoid the overhead of testing for nothing but spaces using an extra PHP statement if possible.

View Replies !   View Related
Simple Regular Expression
I just want the a.bc, but my regular expression seems not working.

<?php
preg_match("/^(http://www.computer.com/)?([^.com]+)/i", "http://www.computer.com/a.bc.com", $data);
echo $data[1];
echo "<p>";
echo $data[2]
?>

View Replies !   View Related
Regular Expression Odd Characters
I'm trying to write  code to take of all the words that had odd characters like (&,%,$,...etc)all the non english letters from my list. therefore I was trying to use the eregi function but I don't know why its not doing the work i need. below is what I used:

if (eregi("^[a-z0-9]",$str))
  echo "Proper English word"

View Replies !   View Related
Regular Expression <h1> Extract
I need some help with regular expression, what I want is to take all the code from the <h1> tag and separate it. here is what I want:

there is alot of html code and tags such as <img> <br><p> etc etc// but I only want to extract all <h1> tags data..

<h1><a href="http://yahoo.com/" target="_blank" class="myClass">my keyword</a></h1>

I want to have the URL/link receive in $url variable and anhor in $anchor variable.

View Replies !   View Related
Regular Expression Matching
I'm trying to write a regular expression, but i'm coming up dunce every time. I'm using some tutorials but I just haven't understood it properly yet. I'm trying to look for a string starting with 07, and if it does start with 07, keep the first 11 positions, and discard the rest. Can someone please give me a hint?

View Replies !   View Related

Copyright © 2005-08 www.BigResource.com, All rights reserved