Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

point in regular expressions php

Hi,

I have the following code

preg_match_all('.u.',"Fuse",$matches);
print_r ($matches);

Open in new window


Why it not return the word  "use" ?
0
joyacv2
Asked:
joyacv2
  • 5
  • 5
1 Solution
 
Dan CraciunIT ConsultantCommented:
It should return 'Fus'.

And you forgot the delimiters:

preg_match_all('/.u./',"Fuse",$matches);

You're searching for:
any character
u
any character

HTH,
Dan
0
 
joyacv2Author Commented:
yes, you are right i want to say Fus, the script returns

Array ( [0] => Array ( [0] => us ) )

Why don't return Fus?
0
 
joyacv2Author Commented:
Hi Dan, why I have to use /?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Dan CraciunIT ConsultantCommented:
Put the delimiters and the result will be:
Array ( [0] => Array ( [0] => Fus ) )
0
 
joyacv2Author Commented:
now works, what is the purpose of the /?
0
 
Dan CraciunIT ConsultantCommented:
It's the custom in PHP. You don't have to use //, you can use %%, !! etc

I guess the reason is that you can specify the modifiers/flags after the last delimiter (for ex /expr/i will make the search case insensitive).

It's the way sed/awk use regular expressions and probably someone thought it would be easier to keep that format.

http://us.php.net/manual/en/pcre.examples.php
http://us.php.net/manual/en/regexp.reference.delimiters.php
0
 
joyacv2Author Commented:
sorry, but i am a little confuse, i am reading a book for regular expressions and not mention anything about adding a / before .

Can you explain me a little bit about that?
0
 
Dan CraciunIT ConsultantCommented:
Most languages do not require delimiters, but PHP does.

Read this: http://us.php.net/manual/en/regexp.reference.delimiters.php
0
 
joyacv2Author Commented:
perfect!!!
0
 
Dan CraciunIT ConsultantCommented:
BTW, I recommend this site: http://www.regular-expressions.info/tutorial.html

I used it a lot while learning.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now