I am trying to find everything in a paragraph that is not abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 and not space / /gi
/[^a-zA-Z0-9]|[^ ]/gi
the above doesn't work!
You could also try with:
/[^a-zA-Z0-9\s]/gi
If you only want to exclude spaces use:
[^ ]*
Test the regex here if you want.
try ^[\d\w]*$ or ^[\w]*$
as reg' Expression means from ^(start) to $(end) match 0-9a-zA-Z only
for c++ ansistring="^[\\d\\w]*$";
You can use this for
am trying to find everything in a paragraph that is not abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 and not space / /gi
replaceAll("[^A-Za-z0-9\\s]", "")
Related
I have a string like this:
abcabcdeabc...STRING INSIDE...xyz
I want to find "...STRING INSIDE..." so I'm using the regex below to match it:
(?<=abc).*(?=xyz)
The issue is there are duplicated "abc" in the string so it returns "abcdeabc...STRING INSIDE..." but I only want to match anything between the last "abc" and "xyz". Is this possible? And if yes, how can I achieve this? Thank you.
Try it here:
https://regex101.com/r/gS9Xso/3
Try this pattern:
.*(?<=abc)(.*)(?=xyz)
The leading .* will consume everything up until the last abc, then the number will be captured.
Demo
We can also try using the following pattern:
.*abc(.*?)xyz
Here is a demo for the second pattern:
Demo
This should work well.
[^\d]*abc(\d+)xyz[^\d]*
See it on Debuggex
I need a regexp that would find and replace the following in Edit++:
Replace all \n with the syntax .\n, but where there is no space before the \n. So all syntax _\n (_ means space here) would be left intact. Any ideas?
I don't know about Edit++, but I'd do it by searching for "([^ ])\n", and replacing with "$1.\n".
No idea about Edit++ but the regular expression should be to look for the absence of space (specified by [^ ] at the end of line (specified by $, and append .. For example, in sed, the following takes care of it: sed 's/[^ ]$/&./'.
Try this:
(?<=[^\s]{1,1})\n|$
Demo here.
I'd like to set up a regular expression that matches certain patterns for a URL:
http://www.domain.com/folder1/folder2/anything/anything/index.html
This matches, and gets the job done:
/^http:\/\/www\.domain\.com\/folder1\/folder2\/.*\/.*\/index\.html([\?#].*)?$/.test(location.href)
I'm unsure how to limit the wildcards to one folder each. So how can I prevent the following from matching:
http://www.domain.com/folder1/folder2/folder3/folder4/folder5/index.html
(note: folder 5+ is what I want to prevent)
Thanks!
Try this regular expression:
/^http:\/\/www\.domain\.com\/(?:\w+\/){1,3}index\.html([\?#].*)?$/
Change the number 3 to the maximum depth of folders possible.
. matches any character.
[^/] matches any characters except /.
Since the / character marks the begining and end of regex literals, you may have to escape them like this: [^\/].
So, replacing .* by [^\/]* will do what you want:
/^http:\/\/www\.domain\.com\/folder1\/folder2\/[^\/]*\/[^\/]*\/index\.html([\?#].*)?$/.test(location.href)
/^http:\/\/www\.domain\.com\/folder1\/folder2\/[^/]*\/[^/]*\/index\.html([\?#].*)?$/
I don't remember whether we should escape the slashes within the []. I don't think so.
EDIT: Aknoledging tom's comment using + instead of *:
/^http:\/\/www\.domain\.com\/folder1\/folder2\/[^/]+\/[^/]+\/index\.html([\?#].*)?$/
/^http:\/\/www\.domain\.com\/\([^/]*\/\)\{2\}/
And you can change 2 to whatever number of directories you want to match.
You may use:
^http:\/\/www\.domain\.com\/folder1\/folder2\/(\w*\/){2}index\.html([\?#].*)?$/.test(location.href)
I need a regex to match something this:
<a space><any character/s>#<any character/s><a space>
Yes, it's a very very basic email parser.
Thanks!
Something like this? /^ [^#]+#[^ ]+ $/
The square brackets indicate a character class, which is the characters that can be present there. So, your regex would match .#. or *#*. Instead, try "\ .*#.*\ " (quotes to show the space at the end, don't include them inside your regex.
For testing e-mail, you might use the regex described here:
\b[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,4}\b
It still doesn't cover 100% of e-mails, but the comprehensive version is fairly involved.
^ .+#.+ $
This translates to "the start of the string is followed by a space, one or more characters, the # symbol, one or more characters, and the last character in the string is a space."
I have many lines that start like:
text.1
text.2
othertext.21
anothertext.50
dfgtext.161
what I need is to find the lines that has only .1 (not .21, not 11), only anytext.1
I use notepad++
Thanks,
You just have to match the end of the line, so try with \.1$
If it's any text + .1 then try the follwing regex
.+?\.1$
Assuming Notepad++ supports $, the end of line match, \.1$ should work for you.