how would i write an if statement that would find phone numbers and store them to a variable. Here is what i have so far but its not working.
if (preg_match('/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[...
I'd like to test whether a string contains "Kansas" followed by anything other than " State".
Examples:
"I am from Kansas" true
"Kansas State is great" false
"Kansas is a state" true
"Kansas Kansas State" true
"Kansas State vs Kansas" true
"I'm from Kansas State" false
"KansasState" true
...
I want to perform a regex using grouping. I am only interested in the grouping, its all I want returned. Is this possible?
$haystack = '<a href="/foo.php">Go To Foo</a>';
$needle = '/href="(.*)">/';
preg_match($needle,$haystack,$matches);
print_r($matches);
//Outputs
//Array ( [0] => href="/foo.php"> [1] => /foo.php )
//I want:
//A...
I'm desperately searching for regular expressions that match these scenarios:
1) Match alternating chars
I've a string like "This is my foobababababaf string" - and I want to match "babababa"
Only thing I know is the length of the fragment to search - I don't know what chars/digits that might be - but they are alternating.
I've reall...
I'm using preg_* in PHP to search for the pattern <!-- %{data=THIS GETS MATCHED}% --> and pull out the matched text.
The pattern for this is:
preg_match('#<!-- %{' . $knownString . '\s*=\s*(.*?)}% -->#', ...)
What I would like it to do is search across multiple lines for the string. For example:
<!-- %{data=
THIS GETS
MATCHED AND
RE...
I would like to use UltraEdit regular expression (perl) to replace the following text with some other text in a bunch of html files:
<style type="text/css">
#some-id{}
.some-class{}
//many other css styles follow
</style>
I tried to use <style type="text/css">.*</style> but of course it wouldn't match anything because the dot matc...
I'm trying to create a Regular Expression to match "wiki style" lists as in (using preg_replace_callback() ):
* List Item 1
* List Item 2
*# List Item 2.1
*# List Item 2.2
* List Item 3
Asterisks denote Unordered Lists while Number-Signs denote Ordered Lists. I'm trying to get this so it can match infinite depth and so that...
I'm trying to use a regular expression as below:
preg_match_all('|<table.*</table>|',$html,$matches, PREG_SET_ORDER);
But this is not working, and I think the problem is the new line inside the string $html.
Could someone tell me a work around?
EDIT: I've realized that it's not right to use regex to parse HTML. Thanks to those who to...
Hi,
I need a regex expression (PCRE) to match a integer number inside a string, being the string like : image89.jpg
I've tried many options without success.
I'm using preg_replace() by the way
My last attempt :
preg_replace('(\d+)', '$1', 'image89.jpg');
...
I'm trying to compile PCRE (v8.02) for Windows x64, using Vs2008.
The "NON-UNIX-USE" file tells me to use cmake to generate a .sln fle.
That works.
When I run the build it succeeds, with 91 warnings.
All appear to be size conversion warnings.
Am I doing something wrong?
Should I expect all these warnings?
Has anyone else built PCR...
Hi,
I have a variable, $var, that contains a string of characters, this is a dynamic variable that contains the values from inputs.
$var could be 'abc', or $var could be 'blu',
I want to match the string inside variable against an array, and return all the matches.
$array = array("blue", "red", "green");
What is the correct syntax...
I am trying to match any url that has /images/ , /styles/ , or /scripts/ in a lighttpd $HTTP["url"] statement. How could this be done? I am currently using "^/images/" , etc. and it's only working if that directory is in the beginning of the URL.
...
I have a small chunk of coding I need to take from ereg to preg_match. Here is the code.
function be_file_list($d, $x) {
foreach (array_diff(scandir($d), array('.', '..')) as $f) {
if (is_file($d . '/' . $f) && (($x) ? ereg($x.'$',$f) : 1)) {
$l[] = $f;
}
}
return $l;
}
This code works as expec...
Well, there are other ways (hmmm... or rather working ways) to do it, but the question is why does this one fail?
/
\A # start of the string
( # group 1
(?: # group 2
[^()]* # something other than parentheses (greedy)
| # or
\( (?1) \) # parenthesized group 1
) ...
Is there a canonical function/method for escaping a string to be used in a preg_, such that any special PCRE characters will be interpreted as literal. Basically, a know way to ensure that something like
I am a fancy string (well, that guy ... said I was fancy)
is transformed into
I am a fancy string \(well, that guy \.\.\. said I ...
I have a string 1/temperatoA,2/CelcieusB!23/33/44,55/66/77 and I would like to extract the words temperatoA and CelcieusB.
I have this regular expression (\d+/(\w+),?)*! but I only get the match 1/temperatoA,2/CelcieusB!
Why?
...
hi,
since eregi replace was deprecated on version 5.3 i want to make my program compatible with new version of php
http://php.net/manual/en/function.eregi-replace.php
so, i'm trying to use preg_replace like this
preg_replace(",",'','20,000.00');
but come with error
i'm familiar with eregi_replace(',','','20,000.00'); i'm not familia...
Hi all,
I would like to know, is there a conversion library for converting string patterns to PCRE regular Expression patterns.
Sample Patterns:
application/ms-tnef ARKADMIN_GET_ 34 ^MAIL FROM|3a| ?
2|
Thanks in advance.
...
Hello, I want to capture named substring with the pcre++ library.
I know the pcre library has the functionality for this, but pcre++ has not implemented this.
This is was I have now (just a simple example):
pcrepp::Pcre regex("test (?P<groupName>bla)");
if (regex.search("test bla"))
{
// Get matched group by name
int pos = pc...
I'm a complete novice when it comes to regex. Could someone help me convert the following expression to preg?
ereg('[a-zA-Z0-9]+[[:punct:]]+', $password)
An explanation to accompany any solution would be especially useful!!!!
...