Validation of a CQ5 dialog through regex - regex

I have a widget for my dialog, which I would like to validate using a Regex.
Here are its properties:
<widget
regex="/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]#[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/"
regexText="Please enter a valid email address"
xtype="textfield"
fieldLabel="Email"
name="./email"
allowBlank="false"/>
Whenever I input a valid email address, it always returns false. I have admittedly zero prior knowledge on working with regex.
Where am I going wrong?

Try the following regex, this one works for me.
/^[A-za-z0-9]+[\\._]*[A-za-z0-9]*#[A-za-z.-]+[\\.]+[A-Za-z]{2,4}$/

For people with similar issues who are searching this on google:
Open CRXDE and edit the dialog by double-clicking on the dialog icon. It will open a special dialog editor. Select the text field you want to edit and enter the regex in the UI. Enter only a Javascript-valid regex. Find and use a Regex tester on google if you need to, to ensure it is valid. Save the dialog then look at the JCR (remember to refresh CRXDE as it caches old content) or export using package manager.
Some common issues:
Must start and end with "/".
/foobar/
All XML characters need to be escaped. I don't know why, it seems very odd to me.
/Surf&Turf/
/<html>/
Slashes must be escaped with backslash. Backslash must be escaped with backslash. (Just use character classes, it's cleaner anyway).
/http:\\/\\/www\\.google\\.com/
Good luck!

I guess the following should work for you regex:- /^[a-zA-Z][\\w\.-]*[a-zA-Z0-9]#[a-zA-Z0-9][\\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/

Here is one that runs in adobe cq5, try it out
/^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*#[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$/

Related

Is there a way of making sublime snippets with a regex trigger?

I'm trying to make a snippet that is triggered by a regular expression. Is it even possible in Sublime Text 3?
I've tried this but it doesn't trigger. I've already checked that sublime replaces it correctly with the Find and Replace option.
<snippet>
<content><![CDATA[$1_$2
]]></content>
<tabTrigger>([a-zA-z])(\d)</tabTrigger>
<description></description>
<scope>text.tex.latex</scope>
</snippet>
I want my snippet to be triggered by pressing tab after any word that matches a character followed by a digit and replace it with the character, a _, and the digit.
Examples
a1 turns into a_1
X0 turns into X_0
The trigger text for a sublime-snippet file has to be literal text in order to trigger; Sublime won't match it based on a regular expression. To do something like that you need a plugin command that is bound to the tab key (for example) that triggers a command that examines the text to the left of the cursor to see if it matches the regex and then expand it based on that.
I'm not aware of a general purpose package that does something like this (although Emmet does this for expanding HTML tags, it's not generic and is known to interfere with regular tab completion) but there may be one listed on package control.
This forum post on the Sublime forum includes a sample plugin that does something very similar to this that may be useful as a starting point for something like this, though. Based on your examples above, it should do what you want as long as you swap the scope in the example for the one from your snippet so that it triggeres in LaTeX files instead of Markdown. You may want to rename the command as well in that case.
[Edit] If you're not sure how to use plugin in Sublime Text, this video covers how to do it.
My guess is that, maybe this expression,
(?i)(?<=<tabTrigger>[a-z])(?=\d<\/tabTrigger>)
replaced with _ might be something that you might have in mind, for instance.
If you wish to explore/simplify/modify the expression, it's been
explained on the top right panel of
regex101.com. If you'd like, you
can also watch in this
link, how it would match
against some sample inputs.

Google Form Validate a specific URL Regex

I am creating a google form and trying to create a regex on of the fields because I need them to enter a profile link from a specific website. I'm a beginner with regex and this is what I have come up with:
/^(http:\/\/)?(steamcommunity\.com\/id\/)*\/?$/
But when I go to enter a test link such as: http://steamcommunity.com/id/bagzli it fails it. I don't understand what is wrong about it.
You missed a dot (meaning any character) after the (/id\). Try this:
/^(http:\/\/)?(steamcommunity\.com\/id\/).*\/?$/
^-- added
The ultimate goal of what I was trying to accomplish is to ensure that certain text was entered in the box. I thought I had to use Regex to accomplish that, but google forms also has "Text Contains" feature which I made use of to solve my problem. The regex by Zoff Dino did not work, I am not sure why as it seems completely correct.
I will mark this as resolved as I managed to get my answer, even if it was not via regex.

Filter by regex example

Could anyone provide an example of a regex filter for the Google Chrome Developer toolbar?
I especially need exclusion. I've tried many regexes, but somehow they don't seem to work:
It turned out that Google Chrome actually didn't support this until early 2015, see Google Code issue. With newer versions it works great, for example excluding everything that contains banners:
/^(?!.*?banners)/
It's possible -- at least in Chrome 58 Dev. You just need to wrap your regex with forward-slashes: /my-regex-string/
For example, this is one I'm currently using: /^(.(?!fallback font))+$/
It successfully filters out any messages that contain the substring "fallback font".
EDIT
Something else to note is that if you want to use the ^ (caret) symbol to search from the start of the log message, you have to first match the "fileName.js?someUrlParam:lineNumber " part of the string.
That is to say, the regex is matching against not just the log message, but also the stack-entry for the line which made the log.
So this is the regex I use to match all log messages where the actual message starts with "Dog":
/^.+?:[0-9]+ Dog/
The negative or exclusion case is much easier to write and think about when using the DevTool's native syntax. To provide the exclusion logic you need, simply use this:
-/app/ -/some\sother\sregex/
The "-" prior to the regex makes the result negative.
Your expression should not contain the forward slashes and /s, these are not needed for crafting a filter.
I believe your regex should finally read:
!(appl)
Depending on what exactly you want to filter.
The regex above will filter out all lines without the string "appl" in them.
edit: apparently exclusion is not supported?

Regex to change old url to new with wordpress redirection

I want to redirect for example
www.mydomain.com/my-profile.html?userId=18681
to
www.mydomain.com/members
what shall i put in my Source URL?
I have more than 2000 404 errors on webmaster because i changed from cms to cms, so i want to fix my redirection regex so not to enter the errors one bye one because I have
/my-profile.html?userId=18681
/my-profile.html?userId=12451
/my-profile.html?userId=9251
How can i make it general so it automatic redirects all to www.mydomain.com/members
I use this plugin http://wordpress.org/plugins/redirection/
I'm not sure how you're going about implementing the redirect. But from a purely regex standpoint, If I wanted to convert the top url format to the one you put below it, here is the find-and-replace format I would use:
s/(my-.+\d+)$/members/
So find 'my-', then one or more of any character, then ENDING with one or more digits. Replace that (starting with my- and ending with the digits) with 'members'.
Sorry if this does not solve your issue, and keep in mind this is 'perl compatible' format for regex, find-and-replace may (likely) be a formatted differently for the language you are implementing this with.

In Yahoo-Pipes, how to use regex when you can't see non-printable characters and html tags?

I keeping having the problem trying to extract data using regex whereas my result is not what I wanted because there might be some newlines, spaces, html tags, etc in the string, but is there anyway to actually see what is in the string, the debugger seems to show only the real text. How do you deal with this?
If the content of the string is HTML then debugger gives you a choice of viewing "HTML" or "Source". Source should show you any HTML tags that are there.
However if your concern is white space, this may not be enough. Your only option is to "view source" on the original page.
The best course of action is to explicitly handle these possibilities in your regex. For example, if you think you might be getting white space in your target string, use the \s* pattern in the critical positions. That will match zero or more spaces, tabs, and new lines (you must also have the "s" option checked in the regex panel for new lines).
However, without specific examples of source text and the regex you are using - advice can only be generic.
What I do is use a regex tester (whichever uses the same regex engine that you are using) and I test my pattern on it. I've tried using text editors that display invisible characters but to me they only add to the confusion.
So I just go by trial and error. For instance, if a line ends in:
</a>
Then I'll try the following patterns on the regex tester until I find one that works:
</a>.
</a>..
</a>\s
</a>\s*
</a>\n
</a>\r
</a>\r\n
Etc.