Regex for Punctuation (Section sign) in PHP [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to create a regex that finds § in a string.
The section sign has unicode U+00A7 ,html sect and ascii value 245;
But I wonder if /(\245)/ would work

245 sits outside the ASCII character set (which is 7-bit), so I'm not sure where that value is from?
For the purposes of matching with preg_match, you can either just include the value as-is within the regex, or if you prefer not to, use \x{A7}.

This § is 167 decimal (take your pick):
as octal \0247
as hex \xA7
Either one can be used as a literal in regular expressions.
Unicode starts at characters >= 0x100, so you probably don't need the
Unicode modifier form //u unless PHP redefines Unicode.

Related

Why is the Regex for my product's code not working? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to do Regex code for product's code in VSCode's HTML. My product's code has the following conditions:
Required enter 6 characters
First 2 characters must be letter and uppercase
Next 4 characters must be numbers.
I have tried this regular expression and it doesn't work:
^[A-Z]{2}+\[0-9]{4}$
Your regex should be:
^[A-Z]{2}[0-9]{4}$
This corrects the escaping of your character class; that made it no longer a character class but a series of characters to match in the regex, ending with 4 ]s. The + also is not needed as the {2} is stating only 2 uppercase alpha characters are allowed.
You can also swap the [0-9] with \d which is the metacharacter for an integer. With PHP regexs you also need delimiters so something like:
/^[A-Z]{2}\d{4}$/
could be used in preg_match.

PHP - preg_match explanation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Im a beginner in PHP I just want to ask can someone explain to me this line of code.
(preg_match('/^\w{5,}$/', $username))
Thankyou in advance. :) Your answer is so much appreciated. :)
Your PHP match string is
/^\w{5,}$/
and a PHP match string is surrounded by / characters which are not part of the RegEx string itself.
According to the comments your problem is about understanding regular expressions, not PHP.
^ is the beginning of the line, correct
$ is the end of the line, correct
\w Any word character (letter, number, underscore)
a{5,} does mean 5 or more characters 'a'
Therefore: If there are 5 or more any word characters in the username the function returns a positive result.
Or even easier: A username needs to contain at least five any word characters.
Learn more about regular expressions and how they work. Some explanation can be found in this comment.

Regular expression for special characters and numericals [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Want a regular expression that matches only special characters and numericals..
Consider an example
$sting1 = '($001)';
$sting2 = '($001test)';
So only $string1 should match in this case and not the second one.
As second string has alphabets present in it, that should not match..
How about:
preg_match('/^\P{L}+$/u', $str);
Where \P{L} stands for any character that is not a letter.
Below is a PCRE regex which can match special characters, numericals and white space.
[^[:alpha:]]+
If you need to omit whitespaces then,
[^[:alpha:]\s]+
You can check out the demo here.

Regex involving nested delimiters/quotes [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a string that is enclosed by either apostrophes or double-quotes. Within the string, the other ('non-enclosing') character may appear. I'd like to extract the contents of the string using regex.
Example: string = "isn't"; and I want to extract isn't.
Using /[\'"]([^\'"]*)[\'"]/ doesn't work because it doesn't impose the constraint that the string is opened and closed by the same character.
Using /([\'"])([^\'"]*)(?1)/ fixes that, but disallows the 'other' character from occurring within the string. I need something like /([\'"])(!(?1)*)(?1)/ but how do I write that?
As a bonus, can I avoid capturing the opening character so that ?1 contains the string contents?
Group index 1 contains the characters which are present within the double quotes or single quotes.
(?|"([^"]*)"|'([^']*)')
DEMO
OR
You could use the below regex also,
([\'"])((?:(?!\1).)++)\1
DEMO
Pattern Explanation:
([\'"]) Captures the starting single or double quotes.
((?:(?!\1).)+) Captures one or more characters but not of the character which was present inside the group index 1.
\1 Must end with a character captured by the group 1.

write special string to url [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how to write special string such as %31 to url.
Your tags suggest a bit of indecisiveness when it comes to the language you are using, so I'll assume PHP.
Use the urlencode function to escape illegal and special characters for inclusion in a URL.
You just need to encode the % to %25 - so %31 turns to %2531.
Just lookup any ASCII table for the decimal value of the character.
Just encode the percent sign itself so that when the browser parses the string it translates it properly.
Here's a link with various characters and their encoding:
http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
urlencode is probably your friend :)

Categories