Solved

point in regular expressions php

Posted on 2014-04-15
10
179 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
  • 5
  • 5
10 Comments
 
LVL 34

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
 
LVL 34

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 34

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 34

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 34

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now