Regex: pattern contains 0 or more special characters

this syntax returns an array with a word key.


ex. $array['item']

I want the return value in this form but I want to search for a word that may or may not contain parentheses (with values in between).

"hello(some text and line breaks)"

What is the syntax for this?

-------------Problems Reply------------


will match words that can optionally be directly followed by a parenthesized text. Nested parentheses are not allowed.

\w+ # Match alnum characters
(?: # Match the following (non-capturing) group:
\( # literal (
[^)]* # any number of characters except )
\) # literal )
)? # End of group; make it optional


or if your regex engine defaults parentheses to normal character


Category:php Views:1 Time:2011-01-13
Tags: php regex

Related post

  • Regex to allow text, some special characters and keep below a specified length 2009-12-16

    I'm trying to create a validation expression that checks the length of an input and allows text and punctuation marks (e.g. , ? ; : ! " £ $ % ) What I have come up with so far is "^\s*(\w\s*){1,2046}\s*$" but this won't allow any punctuation marks. T

  • C# Regex to detect usage of Special characters 2011-07-04

    I want to filter out special characters in C#. Basically i want to allow A-Z, a-z, 0-9, hyphen, underscore, (, ), commas, spaces, \, /, spaces. Everything else is not allowed. I have come up with the following regex -> [a-zA-Z0-9-\b/(),_\s]* but t

  • .Net Regex to highlight keywords including special characters 2011-08-01

    Keywords highlighters that are available on the internet do not highlight special characters. e.g. How can I make them hightlight any characters. e.g. C++ ----

  • Javascript RegEx for Numbers Only (no special characters) 2012-03-14

    I'm trying to find a RegEx that will allow the digits 0-9 ONLY and not special characters. Is this an impossibility since pressing Shift + 2 is still a digit? I've used the following: return /[0-9]|\./.test(String.fromCharCode(event.keyCode)); Which

  • Javascript Regex to remove any spaces, special characters and numbers 2014-09-26

    At the moment I have the following $scope.user.username.replace(/[\s]/g, ''); This removes and special characters and spaces, I need to add in the ability to prevent numbers and special characters too but I can't quite grasp how Regex works. Would so

  • regex to find substring between special characters 2011-01-24

    I am running into this problem in Java. I have data strings that contain entities enclosed between & and ; For e.g. &Text.ABC;, &Links.InsertSomething; These entities can be anything from the ini file we have. I need to find these string

  • Regex Pattern for String including newline characters 2011-12-17

    I am looking for a regex pattern that will return a match from %PDF-1.2 to and including %%EOF in the string below. So far my patterns don't seem to work. DOCUMENTS ACCEPTED 001//201//0E9136614////ACME 107 PTY LTD//8 **E10 End of validation report**

  • java regex to escape oracle sql special characters 2012-03-23

    I want to escape all the special character is an sql query. So i created thi regex: Pattern p1 = Pattern.compile("\\{ | \\} | \\\\ | \\, | \\& | \\? |" + " \\( | \\) | \\[ | \\] | \\- | \\; | \\~ | \\| | \\ $ | " + "\\! | \\< | \\> | \\* |

  • RegEx Pattern to Match Only Certain Characters 2009-10-12

    I'm a newbie to RegEx, and this particular issue is flummoxing me. This is for use with a JavaScript function. I need to validate an input so that it matches only this criteria: Letters A-Z (upper and lowercase) Numbers 0-9 The following additional c

  • Can anyone tell me the regex for excluding numbers and special characters in ASP.NET? 2011-04-14

    How do I get the regular expression for excluding special charaters and numbers? Thanks in advance. --------------Solutions------------- possible regex [^()[\]{}*&^%$#@!]+ this will match anything but ()[]{}*&^%$#@! the [^...]+ is a "any char

  • How do I write a regex in PHP to remove special characters? 2009-04-13

    I'm pretty new to PHP, and I noticed there are many different ways of handling regular expressions. This is what I'm currently using: $replace = array(" ",".",",","'","@"); $newString = str_replace($replace,"_",$join); $join = "the original string i'

  • How to check for special characters using regex 2010-02-17

    NET. I have created a regex validator to check for special characters means I donot want any special characters in username. The following is the code Regex objAlphaPattern = new Regex(@"[[email protected]]"); bool sts = objAlphaPattern.IsMatch(username)

  • Need to alter regex to allow for special characters 2009-06-10

    I have the following bit of code in my htaccess that will allow a users ID to only be alphanumeric and include underscores and hyphens: RewriteRule ^([A-Za-z0-9_-]+)$ profile.php?ID=$1 [QSA,L] I've recently imported over 1000 usernames from a social

  • regex to remove special characters, spaces and number if first character 2015-02-11

    I'm looking for a regex in javascript to remove special characters, spaces and numbers but only if its the first character. For example the strings below 1 step for man & 2 steps for others 123! step for 1 man & 2 steps for others 123! I want

  • matching a string between special characters in JAVA 2011-07-14

    I want to match n number of characters between a "<" and ">" characters. For example, I want to be able to match <a href = "image1.jpg"> or <a href = "; essentially with the same pattern. This is becaus

  • How to use regex to check that user input does not consist of special characters only? 2010-09-06

    How to put a validation over a field which wouldn't allow only special characters, that means AB#,[email protected],@#ASD is allowed but @#$^& or # is not allowed. I need the RegEx for this validation. --------------Solutions------------- str.match(/^[A-Z#@,]

  • Regex to check only capital letters, two special characters (& and Ñ) & without any space between 2010-10-20

    I am using below code snippet to validate my input string with: only capital letters, numbers and two special characters (those are & and Ñ) & without any space between. var validpattern = new RegExp('[^A-Z0-9\d&Ñ]'); if (enteredID.match(

  • regex: How to escape backslashes and special characters? 2011-01-11

    Is there a way to escape ( or protect ) special characters in a regular expression? What I would like to do is to create a simple regex tester: import java.util.regex.*; class TestRegex { public static void main( String ... args ) { System.out.printf

  • Regex match a strong password with two or more special characters 2011-01-12

    I need to regex match a password field using javascript with the following requirements: At least 15 characters two or more lower case letters two or more upper case letters two or more digits two or more of the following special characters: [email protected]#$%^

  • regex with special characters? 2011-03-09

    i am looking for a regex that can contain special chracters like / \ . ' " in short i would like a regex that can match the following: may contain lowercase may contain uppercase may contain a number may contain space may contain / \ . ' " i am makin

Copyright (C), All Rights Reserved.

processed in 0.092 (s). 11 q(s)