Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

point in regular expressions php

Posted on 2014-04-15
10
Medium Priority
?
189 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 2000 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
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.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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…
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

610 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