[PHP] Re: Regex Problem

2009-07-31 Thread Igor Escobar
The solution don't need to be with regex, if anyone can solve this with
other way will be very helpfull .


Regards,
Igor Escobar
Systems Analyst  Interface Designer

+ http://blog.igorescobar.com
+ http://www.igorescobar.com
+ @igorescobar (twitter)





On Fri, Jul 31, 2009 at 2:23 PM, Igor Escobar titiolin...@gmail.com wrote:

 Hi Folks,
 I have a serious problem.

 must create a regular expression against all that is between single quote
 or double quotes. Easy? Ok, i know, but i need that everything must to be
 too an single quote or double quote.

 If i have this SQL command:

 SELECT * FROM TSTRENIC.MEI_ACESSO WHERE UPPER(DS_MEI_ACS) LIKE *'%NOME'
 ASD ' AS'ASD'%' *AND USUARIO = *'oaksdpokasd'asda'* ORDER BY DS_MEI_ACS
 ASC;

 SELECT * FROM TSTRENIC.MEI_ACESSO WHERE USUARIO_DATA BETWEEN *'2007-01-02'
 * AND *'2008-07-08'*

 Anyone have any idea?



 I need an expression which case the fields in bold.


 Regards,
 Igor Escobar
 Systems Analyst  Interface Designer

 + http://blog.igorescobar.com
 + http://www.igorescobar.com
 + @igorescobar (twitter)






[PHP] Re: Regex Problem

2009-07-31 Thread Shawn McKenzie
Igor Escobar wrote:
 The solution don't need to be with regex, if anyone can solve this with
 other way will be very helpfull .
 
 
 Regards,
 Igor Escobar
 Systems Analyst  Interface Designer
 
 + http://blog.igorescobar.com
 + http://www.igorescobar.com
 + @igorescobar (twitter)
 
 
 
 
 
 On Fri, Jul 31, 2009 at 2:23 PM, Igor Escobar titiolin...@gmail.com wrote:
 
 Hi Folks,
 I have a serious problem.

 must create a regular expression against all that is between single quote
 or double quotes. Easy? Ok, i know, but i need that everything must to be
 too an single quote or double quote.

 If i have this SQL command:

 SELECT * FROM TSTRENIC.MEI_ACESSO WHERE UPPER(DS_MEI_ACS) LIKE *'%NOME'
 ASD ' AS'ASD'%' *AND USUARIO = *'oaksdpokasd'asda'* ORDER BY DS_MEI_ACS
 ASC;

 SELECT * FROM TSTRENIC.MEI_ACESSO WHERE USUARIO_DATA BETWEEN *'2007-01-02'
 * AND *'2008-07-08'*

 Anyone have any idea?



 I need an expression which case the fields in bold.


 Regards,
 Igor Escobar
 Systems Analyst  Interface Designer

 + http://blog.igorescobar.com
 + http://www.igorescobar.com
 + @igorescobar (twitter)


Not entirely sure I understand.  You want to BOLD the things contained
in quotes and you put the * there to show that?  If so, this is not tested:

$bolded = preg_replace('#([\'])(.*?)\1#', 'b\1\2\1/b', $text);

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Regex Problem

2009-07-31 Thread Shawn McKenzie
Igor Escobar wrote:
 No no, i need to make an regex to match the bold areas in my string.
 Anything between single quotes or double quotes (including quotes and
 double quotes). Understand?


 Regards,
 Igor Escobar
 Systems Analyst  Interface Designer

 + http://blog.igorescobar.com
 + http://www.igorescobar.com
 + @igorescobar (twitter)

That's not going to happen without some other criteria.  There is no way
for the regex engine to guess at which sets of quotes belong inside
another set of quotes.

-Shawn

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Regex Problem

2009-07-31 Thread Shawn McKenzie
Shawn McKenzie wrote:
 Igor Escobar wrote:
 No no, i need to make an regex to match the bold areas in my string.
 Anything between single quotes or double quotes (including quotes and
 double quotes). Understand?


 Regards,
 Igor Escobar
 Systems Analyst  Interface Designer

 + http://blog.igorescobar.com
 + http://www.igorescobar.com
 + @igorescobar (twitter)

 That's not going to happen without some other criteria.  There is no way
 for the regex engine to guess at which sets of quotes belong inside
 another set of quotes.
 
 -Shawn

Especially since in one of your examples you don't even have an even
number of quotes.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: regex problem

2004-07-01 Thread Lars Torben Wilson
Josh Close wrote:
I'm trying to get a simple regex to work. Here is the test script I have.
#!/usr/bin/php -q
?
$string = hello\nworld\n;
$string = preg_replace(/[^\r]\n/i,\r\n,$string);
First, the short version. You can fix this by using backreferences:
 $string = preg_replace(/([^\r])\n/i, \\1\r\n, $string);
Now, the reason:
preg_replace() replaces everything which matched, so both the \n and
the character before it will be replaced (as they both had to match
to make the pattern match).
Luckily, preg_replace() stores a list of matches, which you can use
either later in the same pattern or in the replace string. This is
called a 'backreference'. You can tell preg_replace() which part(s) of
the pattern you want to store in this fashion by enclosing those parts
in parentheses.
In your case, you want to store the character before the \n which matched,
so you would enclose it in parentheses like so: /([^\r])\n/i. Thereafter
you can refer to that portion of the pattern match with the sequence \1.
If you add another set of parens, you would refer to it with \2...and so
on. You can even nest pattern matches like this, in which case they are
counted by the opening paren. So the replacement string would then become
\\1\r\n. (You need the extra \ in front of \1 to prevent PHP's string
interpolation parsing the \1 before it gets passed to preg_replace()).
A lot more information is available from the manual page on preg_replace():
  http://www.php.net/preg_replace
There is also an extensive pages on pattern syntax:
  http://www.php.net/manual/en/pcre.pattern.syntax.php
Hope this helps,
Torben
$string = addcslashes($string, \r\n);
print $string;
?
This outputs
hell\r\nworl\r\n
so it's removing the char before the \n also.
I just want it to replace a lone \n with \r\n
-Josh
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: regex problem

2004-07-01 Thread Josh Close
Thanks, that's exactly what I was looking for.

-Josh

On Thu, 01 Jul 2004 15:17:41 -0700, Lars Torben Wilson [EMAIL PROTECTED] wrote:
 
 Josh Close wrote:
 
  I'm trying to get a simple regex to work. Here is the test script I have.
 
  #!/usr/bin/php -q
  ?
 
  $string = hello\nworld\n;
  $string = preg_replace(/[^\r]\n/i,\r\n,$string);
 
 First, the short version. You can fix this by using backreferences:
 
   $string = preg_replace(/([^\r])\n/i, \\1\r\n, $string);
 
 Now, the reason:
 
 preg_replace() replaces everything which matched, so both the \n and
 the character before it will be replaced (as they both had to match
 to make the pattern match).
 
 Luckily, preg_replace() stores a list of matches, which you can use
 either later in the same pattern or in the replace string. This is
 called a 'backreference'. You can tell preg_replace() which part(s) of
 the pattern you want to store in this fashion by enclosing those parts
 in parentheses.
 
 In your case, you want to store the character before the \n which matched,
 so you would enclose it in parentheses like so: /([^\r])\n/i. Thereafter
 you can refer to that portion of the pattern match with the sequence \1.
 If you add another set of parens, you would refer to it with \2...and so
 on. You can even nest pattern matches like this, in which case they are
 counted by the opening paren. So the replacement string would then become
 \\1\r\n. (You need the extra \ in front of \1 to prevent PHP's string
 interpolation parsing the \1 before it gets passed to preg_replace()).
 
 A lot more information is available from the manual page on preg_replace():
 
http://www.php.net/preg_replace
 
 There is also an extensive pages on pattern syntax:
 
http://www.php.net/manual/en/pcre.pattern.syntax.php
 
 Hope this helps,
 
 Torben
 
 
 
  $string = addcslashes($string, \r\n);
 
  print $string;
 
  ?
 
  This outputs
 
  hell\r\nworl\r\n
 
  so it's removing the char before the \n also.
 
  I just want it to replace a lone \n with \r\n
 
  -Josh
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: regex problem

2003-08-15 Thread Kae Verens
Merlin wrote:
Hi there,

I have a regex problem.

Basicly I do not want to match:

/dir/test/contact.html

But I do want to match:
/test/contact.html
I tryed this one:
^[!dir]/(.*)/contact(.*).html$
but it does not work and I tryed thousands of other ways plus read
tutorials.
Can anybody please help?
^\/test\/contact.html$

Kae

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: regex problem

2003-08-15 Thread Merlin
 ^\/test\/contact.html$

does not work. I am sorry, I just found that

it has to be:
test/contact.html

and not
dir/test/contact.html

there is no leading slash.

Do you have any other suggestion?

--
lt;IFRAME
SRC=http://saratoga.globosapiens/associates/report_member.php?u=3color=EEE
EEE scrolling=no frameborder=0 TITLE=My travel articles width=330
height=155  ALLOWTRANSPARENCY=truea href=http://www.globosapiens.net;
title=Worldwide Travel CommunityaTravel Communitya/ /IFRAME

Kae Verens [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 Merlin wrote:
  Hi there,
 
  I have a regex problem.
 
  Basicly I do not want to match:
 
  /dir/test/contact.html
 
  But I do want to match:
  /test/contact.html
 
  I tryed this one:
  ^[!dir]/(.*)/contact(.*).html$
 
  but it does not work and I tryed thousands of other ways plus read
  tutorials.
 
  Can anybody please help?

 ^\/test\/contact.html$

 Kae




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: regex problem

2003-08-15 Thread John W. Holmes
Merlin wrote:

^\/test\/contact.html$


does not work. I am sorry, I just found that

it has to be:
test/contact.html
and not
dir/test/contact.html
there is no leading slash.

Do you have any other suggestion?
Are you making this too hard?

if($string = 'test/contact.html')
{ echo 'good'; } else { echo 'bad'; }
??

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals  www.phparch.com





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: regex problem

2003-08-15 Thread Kae Verens
Merlin wrote:
^\/test\/contact.html$


does not work. I am sorry, I just found that

it has to be:
test/contact.html
and not
dir/test/contact.html
there is no leading slash.

Do you have any other suggestion?

*sigh*

^test\/contact.html$

Kae

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: regex problem

2003-08-15 Thread John W. Holmes
John W. Holmes wrote:
Merlin wrote:

^\/test\/contact.html$


does not work. I am sorry, I just found that

it has to be:
test/contact.html
and not
dir/test/contact.html
there is no leading slash.

Do you have any other suggestion?


Are you making this too hard?

if($string = 'test/contact.html')
That's

if($string == 'test/contact.html')

of course... :)

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals  www.phparch.com





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Re: regex problem

2003-08-15 Thread Jay Blanchard
[snip]
 if($string = 'test/contact.html')

That's

if($string == 'test/contact.html')

of course... :)
[/snip]

it could be

if($string == test/contact.html)

couldn't resist :)

Jay

P.S. John, nothing on that thing yet.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: regex problem

2003-08-15 Thread Merlin
ufff.. sorry guys, but I have to explain that better. I appreciate your
help, maybe I did not give enough info.

I am trying to redirect with apache modrewrite. To do this you have to use
regex (not if functions:-)

My problem is, that there are member accounts which look like that:

membername/contact.html

and there are partner accounts which look like this:

partner/name/contact.html

The goal is to redirect only if it is a member account. If I put a
(.*)/contact.html it also matches the partner/
I tryed putting a root / infront, but there is not / root for the url from
apaches point of view.

So I would need a regex which will match the member account, but if the
first word is partner it should
not terminate.

This seems to be a tough one!

Thanx for any help,

Merlin

Kae Verens [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 Merlin wrote:
 ^\/test\/contact.html$
 
 
  does not work. I am sorry, I just found that
 
  it has to be:
  test/contact.html
 
  and not
  dir/test/contact.html
 
  there is no leading slash.
 
  Do you have any other suggestion?
 

 *sigh*

 ^test\/contact.html$

 Kae




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: regex problem

2003-08-15 Thread Kae Verens
Jay Blanchard wrote:
if($string == 'test/contact.html')

it could be

if($string == test/contact.html)
not to start a flame war or anything, but isn't the apostrophe version 
quicker, as it doesn't ask the server to parse the string?

Kae

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: regex problem

2003-08-15 Thread Kae Verens
Merlin wrote:
ufff.. sorry guys, but I have to explain that better. I appreciate your
help, maybe I did not give enough info.
I am trying to redirect with apache modrewrite. To do this you have to use
regex (not if functions:-)
My problem is, that there are member accounts which look like that:

membername/contact.html

and there are partner accounts which look like this:

partner/name/contact.html

The goal is to redirect only if it is a member account. If I put a
(.*)/contact.html it also matches the partner/
I tryed putting a root / infront, but there is not / root for the url from
apaches point of view.
So I would need a regex which will match the member account, but if the
first word is partner it should
not terminate.
This seems to be a tough one!

ah - maybe a chain of rewrites would do?

send all matches of /^partner\/(.*)\/contact.html$/ to partner\/\1\/blah
send all matches of /^(.*)\/contact.html$/ to NEWLOCATION
send all matches of /^partner\/(.*)\/blah$/ to partner\/\1\/contact.html
Kae

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: regex problem

2003-08-15 Thread Marek Kilimajer
So
^[^/]+/[^/]*
or

^!(partner/)

Merlin wrote:

ufff.. sorry guys, but I have to explain that better. I appreciate your
help, maybe I did not give enough info.
I am trying to redirect with apache modrewrite. To do this you have to use
regex (not if functions:-)
My problem is, that there are member accounts which look like that:

membername/contact.html

and there are partner accounts which look like this:

partner/name/contact.html

The goal is to redirect only if it is a member account. If I put a
(.*)/contact.html it also matches the partner/
I tryed putting a root / infront, but there is not / root for the url from
apaches point of view.
So I would need a regex which will match the member account, but if the
first word is partner it should
not terminate.
This seems to be a tough one!

Thanx for any help,

Merlin

Kae Verens [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
Merlin wrote:

^\/test\/contact.html$


does not work. I am sorry, I just found that

it has to be:
test/contact.html
and not
dir/test/contact.html
there is no leading slash.

Do you have any other suggestion?

*sigh*

^test\/contact.html$

Kae







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: regex problem

2003-08-15 Thread Merlin
does not work. Is there not a way to exclude the word partner like you
triede with !(partner) ?

merlin



Marek Kilimajer [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 So
 ^[^/]+/[^/]*

 or

 ^!(partner/)

 Merlin wrote:

  ufff.. sorry guys, but I have to explain that better. I appreciate your
  help, maybe I did not give enough info.
 
  I am trying to redirect with apache modrewrite. To do this you have to
use
  regex (not if functions:-)
 
  My problem is, that there are member accounts which look like that:
 
  membername/contact.html
 
  and there are partner accounts which look like this:
 
  partner/name/contact.html
 
  The goal is to redirect only if it is a member account. If I put a
  (.*)/contact.html it also matches the partner/
  I tryed putting a root / infront, but there is not / root for the url
from
  apaches point of view.
 
  So I would need a regex which will match the member account, but if the
  first word is partner it should
  not terminate.
 
  This seems to be a tough one!
 
  Thanx for any help,
 
  Merlin
 
  Kae Verens [EMAIL PROTECTED] schrieb im Newsbeitrag
  news:[EMAIL PROTECTED]
 
 Merlin wrote:
 
 ^\/test\/contact.html$
 
 
 does not work. I am sorry, I just found that
 
 it has to be:
 test/contact.html
 
 and not
 dir/test/contact.html
 
 there is no leading slash.
 
 Do you have any other suggestion?
 
 
 *sigh*
 
 ^test\/contact.html$
 
 Kae
 
 
 
 
 




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: regex problem

2003-08-15 Thread Merlin
Good idea,

but does not work either - surprisingly! -

There should be a clean way with regex for this task.


Andy regex expert in here?

Merlin



Kae Verens [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 Merlin wrote:
  ufff.. sorry guys, but I have to explain that better. I appreciate your
  help, maybe I did not give enough info.
 
  I am trying to redirect with apache modrewrite. To do this you have to
use
  regex (not if functions:-)
 
  My problem is, that there are member accounts which look like that:
 
  membername/contact.html
 
  and there are partner accounts which look like this:
 
  partner/name/contact.html
 
  The goal is to redirect only if it is a member account. If I put a
  (.*)/contact.html it also matches the partner/
  I tryed putting a root / infront, but there is not / root for the url
from
  apaches point of view.
 
  So I would need a regex which will match the member account, but if the
  first word is partner it should
  not terminate.
 
  This seems to be a tough one!
 

 ah - maybe a chain of rewrites would do?

 send all matches of /^partner\/(.*)\/contact.html$/ to partner\/\1\/blah
 send all matches of /^(.*)\/contact.html$/ to NEWLOCATION
 send all matches of /^partner\/(.*)\/blah$/ to partner\/\1\/contact.html

 Kae




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: regex problem

2003-08-15 Thread Curt Zirzow
* Thus wrote Merlin ([EMAIL PROTECTED]):
 ufff.. sorry guys, but I have to explain that better. I appreciate your
 help, maybe I did not give enough info.
 
 I am trying to redirect with apache modrewrite. To do this you have to use
 regex (not if functions:-)

I'm not sure what you expect since this *is* a php mailing list.

 
 My problem is, that there are member accounts which look like that:
 
 membername/contact.html
 
 and there are partner accounts which look like this:
 
 partner/name/contact.html
 
 The goal is to redirect only if it is a member account. If I put a
 (.*)/contact.html it also matches the partner/
 I tryed putting a root / infront, but there is not / root for the url from
 apaches point of view.
 
 So I would need a regex which will match the member account, but if the
 first word is partner it should
 not terminate.
 
 This seems to be a tough one!

Mod rewrite is a powerful tool and you can accomplish what you are
doing several different ways.  As you can tell most people have
been giving attempts to fix your problem without success. This is
because it is not entirely clear what you need done.


Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: regex problem

2003-08-15 Thread Curt Zirzow
* Thus wrote Kae Verens ([EMAIL PROTECTED]):
 Jay Blanchard wrote:
 if($string == 'test/contact.html')
 
 it could be
 
 if($string == test/contact.html)
 
 not to start a flame war or anything, but isn't the apostrophe version 
 quicker, as it doesn't ask the server to parse the string?

heh, that is true. Although I havn't benched marked it but it
prolly is somewhere around .01 difference :)

your not the one that needs to be flamed, it seems that everytime a
topic of 'regex' is posted there is always 20+ in the thread with
101% of them not doing what the person wants. Not to mention the
OT'ness of the post.

cheers,

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: regex problem

2003-08-15 Thread Wouter van Vliet
So, what you want is to pretty much use this regex

/^(.*)([^\/]+)\/([^\/]+)$/

when matched on this URI, the backreferences will contain

\\1 partner/
\\2 name
\\3 contact.html
\\4 .html

  partner/name/contact.html

I have not tested it, but I just guess it will work ;) Wanna know why? I'll
tell you :D

- It first looks at the beginning of the string and will go on untill a the
next pair of () start (partner/)
- That happens there where there is a string containing any character, but
not a slash (partner)
- as a seperator another slash is added
- it starts to match the last part of the url and looks up untill the end.
Again a string containing no slashes

Hope it does do what I expect it to do .. ;)

Wouter


-Oorspronkelijk bericht-
Van: Merlin [mailto:[EMAIL PROTECTED]
Verzonden: vrijdag 15 augustus 2003 16:21
Aan: [EMAIL PROTECTED]
Onderwerp: [PHP] Re: regex problem


Good idea,

but does not work either - surprisingly! -

There should be a clean way with regex for this task.


Andy regex expert in here?

Merlin



Kae Verens [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 Merlin wrote:
  ufff.. sorry guys, but I have to explain that better. I appreciate your
  help, maybe I did not give enough info.
 
  I am trying to redirect with apache modrewrite. To do this you have to
use
  regex (not if functions:-)
 
  My problem is, that there are member accounts which look like that:
 
  membername/contact.html
 
  and there are partner accounts which look like this:
 
  partner/name/contact.html
 
  The goal is to redirect only if it is a member account. If I put a
  (.*)/contact.html it also matches the partner/
  I tryed putting a root / infront, but there is not / root for the url
from
  apaches point of view.
 
  So I would need a regex which will match the member account, but if the
  first word is partner it should
  not terminate.
 
  This seems to be a tough one!
 

 ah - maybe a chain of rewrites would do?

 send all matches of /^partner\/(.*)\/contact.html$/ to partner\/\1\/blah
 send all matches of /^(.*)\/contact.html$/ to NEWLOCATION
 send all matches of /^partner\/(.*)\/blah$/ to partner\/\1\/contact.html

 Kae




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: regex problem

2003-06-03 Thread Ford, Mike [LSS]
 -Original Message-
 From: Monty [mailto:[EMAIL PROTECTED]
 Sent: 31 May 2003 21:21
 
 If you want the entire string to be tested for digits, you 
 need to add the
 length of the string to the regex pattern:
 
 $length = strlen($data);
 preg_match([0-9]{$length}, $data);

Or anchor the pattern to both start and end of the string:

  preg_match(^[0-9]+$, $data);

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: regex problem

2003-06-01 Thread Monty
I don't understand what it is you're trying to accomplish, so, it's hard to
offer a solution. If you just want to verify whether or not a variable
contains numeric data, why not just use the is_numeric() function:

http://us4.php.net/manual/en/function.is-numeric.php

preg_match() will return TRUE if it finds the pattern ANYWHERE in the
string, so, that's why asdf789 passes the test because it contains digits,
whereas 'asdf' won't pass the test because the numbers 0-9 can't be found
anywhere in that string.

If you want the entire string to be tested for digits, you need to add the
length of the string to the regex pattern:

$length = strlen($data);
preg_match([0-9]{$length}, $data);

Monty

 From: [EMAIL PROTECTED] (Daniel J. Rychlik)
 Newsgroups: php.general
 Date: Sat, 31 May 2003 13:46:44 -0500
 To: [EMAIL PROTECTED]
 Subject: regex problem
 
 Hello,,
 
 I have a preg_match issue matching numbers.  I am currently using
 
 !preg_match ('/([0-9\-\.\#:])/', $_POST['nums1']
 throw error[]
 
 This fails if you use something like ' asdf ' but if you use ' asdf789 ' it
 passes false and does not throw an error.
 This is not the obvious solution  I know its a problem in my regular
 expression.  Should I ONLY be using
 
 ' /([0-9])/ ' ,  ?
 
 Thanks in advance.
 Daniel


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Regex problem

2001-10-25 Thread liljim

Hello Leon,

try this

if (preg_match(/^([[:space:]]*)?\*/s, $string)) {
 echo Match.;
} else {
 echo No match;
}

James

Leon Mergen [EMAIL PROTECTED] wrote in message
002f01c15d2a$e4ca3030$012aa8c0@leon">news:002f01c15d2a$e4ca3030$012aa8c0@leon...
Hi there,

I am camping with a little regular expressions problem...

Problem: I want to check if $variable begins with a * (star), and it doesn't
matter if it starts with plenty of spaces...

My solution:
ereg(^[:space:]*\*,$variable)

But, it doesn't seem to work with the space part... The regex:

ereg(^\*,$variable)

does work, but that doesn't include spaces at the start... How can I extend
this one so that it doesn't matter if there are a lot of spaces at the
begin?

Thanks in advance,

Leon Mergen




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: Regex problem

2001-10-25 Thread Calin Uioreanu

$sNoSpaces = ltrim($variable);
if ('*' == $sNoSpaces[0]) 

--

Regards,
--
Calin Uioreanu
[EMAIL PROTECTED]
Tel: +49 - (0) 89 - 25 55 17 23
http://www.ciao.com
--
Leon Mergen [EMAIL PROTECTED] wrote in message
002f01c15d2a$e4ca3030$012aa8c0@leon">news:002f01c15d2a$e4ca3030$012aa8c0@leon...
Hi there,

I am camping with a little regular expressions problem...

Problem: I want to check if $variable begins with a * (star), and it doesn't
matter if it starts with plenty of spaces...

My solution:
ereg(^[:space:]*\*,$variable)

But, it doesn't seem to work with the space part... The regex:

ereg(^\*,$variable)

does work, but that doesn't include spaces at the start... How can I extend
this one so that it doesn't matter if there are a lot of spaces at the
begin?

Thanks in advance,

Leon Mergen




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]