Regular expression return only certain values PHP

LukeDS

I cant remember what to use to return only a specific part of a string. I have a string like this:-

$str = "return(me or not?)";

I want to get the word which is after (. In this example me will be my result. How can I do this?

I dont think substr is what I am looking for. as substr returns value based on the index you provided. which in this case i dont know the index, it can vary. All I know is that I want to return whatever is after "(" and before the space " ". The index positions will always be different there for i cant use substr(..).

Tobias Xy

This regular expression should do the trick. Since you didn't provide general rules but only an example it might need further changes though.

preg_match('/\((\S+)/', $input, $matches);

$matches[1] contains "me" then.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

php Regular Expression return specific string

Java Regular Expression - allow only certain characters and digits

Search and replace in only certain tags and attributes in XML file by a regular expression

PHP regular expression split with keys and values

PHP for each Loop return only certain elements

XPath run text() through regular expression to return numbers only

Regular expression to find values starting from beginning and after return

Report Builder expression SQL list certain values only

Regular expression that only accepts numbers and certain characters under certain conditions with javascript (Vue.js)

carriage Return regular expression

Regular expression for only numbers

regular expression matching a certain url

Regular expression from certain string

Regular expression that ignores certain characters

Regular Expression to exclude a certain pattern

SQL - after sorting, return only rows with certain consecutive values in a column

Loop through an object and only return certain keys together with their values

HTML/PHP Checkbox Values Only Return "On"

How can I match a regular expression in Python up to a certain character, and return None if not match?

Return only certain columns

PHP function to return only parts of string that contain certain characters?

Is there a built-in PHP function to only return certain array keys with their value?

Regular Expression - Want to find a match for a word but only if it does not appear after certain characters

How to modify a regular expression to validate a text box with letters and numbers only, excluding certain characters like !@#$%^&*+=

PHP regular expression matching

php regular expression breaks

PHP Regular expression is failing

Regular Expression in PHP

Regular Expression not working in PHP