Solved

point in regular expressions php

Posted on 2014-04-15
10
187 Views
Last Modified: 2014-04-15
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
Comment
Question by:joyacv2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 40002464
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
 
LVL 1

Author Comment

by:joyacv2
ID: 40002471
yes, you are right i want to say Fus, the script returns

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

Why don't return Fus?
0
 
LVL 1

Author Comment

by:joyacv2
ID: 40002475
Hi Dan, why I have to use /?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40002476
Put the delimiters and the result will be:
Array ( [0] => Array ( [0] => Fus ) )
0
 
LVL 1

Author Comment

by:joyacv2
ID: 40002481
now works, what is the purpose of the /?
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40002488
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
 
LVL 1

Author Comment

by:joyacv2
ID: 40002498
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
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40002501
Most languages do not require delimiters, but PHP does.

Read this: http://us.php.net/manual/en/regexp.reference.delimiters.php
0
 
LVL 1

Author Closing Comment

by:joyacv2
ID: 40002504
perfect!!!
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40002508
BTW, I recommend this site: http://www.regular-expressions.info/tutorial.html

I used it a lot while learning.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question