PHP regular expression to JSP?

Hi there,
I have the following PHP regular expression, and was looking for tips on how to create an equivalent in JSP using the 1.3.1 API. This has been causing me problems since the regex package didn't arrive until 1.4.
preg_match("/^(([\w\-\_])+(\.)*)+\@([\w\-\_]+\.)+[A-Za-z]{2,}$/i", $theAddress)Basically, it checks to make sure a valid email address pattern has been input.
Any help would be appreciated!
Thanks!

Though I donno about PHP and the related stuff that you've posted, I can help you by providing a JS function that you can invoke to check for the valid format of an e-mail ID, I guess if this is what you want.
function isEmail (s)
    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}'s' is the e-mail ID string that you want to check.
Hope you're assisted.
fun_one

Similar Messages

  • Regular expressions using jsp

    Hello Techies,
    I am having a text area inside a jsp file. When ever the end user gives input it must be submitted to the server.
    The real problem is when the end user gives special characters and double-quotes in this text area, jsp is preforming in abnormal way.
    Can u guys tell me how to resolve this issue. i.e how to solve regular expressions in jsp.
    Even though the end user gives special characters or double quotes we should take only the content.
    Looking forward for u reply.
    regards,
    Ramu

    The real problem is when the end user gives special characters and double-quotes in this text area, jsp is preforming in abnormal way.What do you mean with "jsp is preforming in abnormal way" ?
    A arbitrary JSP does not care about double-quotes.
    Can u guys tell me how to resolve this issue. i.e how to solve regular expressions in jsp.Usually the same way as you do it in a poj class.
    Nobody here knows how your JSP looks like and who handles the request when the form is submited or even who generates the model of the data displayed by your JSP.
    You have to provide us with more details.

  • PHP Regular Expressions

    I am trying to write a script that searches for image tags
    and checks for alt tags within them. I am using preg_match_all to
    find all the img tags but i am messing up somewhere on my regular
    expression pattern.
    I seriously just started learning these expressions days ago
    so i really do not know what i am doing here. For some reason my
    current expression: /<img.+\/>./ Doesnt find the next >
    after finding the first <img tag. It gets like the second or
    third one. Shouldnt it cut it off after it finds the first >?
    In addition, my other expression (for extracgting the src tag
    doesnt stop after the second quatation. Insead it goes for a few
    more. /src=\".*\"/ is what i have now.
    What do i need to fix so that the results i get back dont
    include anything after the first > or the second quation
    mark?

    barbedwire103 wrote:
    > What do i need to fix so that the results i get back
    dont include anything
    > after the first > or the second quation mark?
    /<img[^>]+>/
    /src\s?=\s?"[^"]+"/
    David Powers
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    http://foundationphp.com/

  • PHP Regular Expression of URL in text

    I have some text that is displaying from a database table and
    inside
    that text is a web address (i.e.,
    http://www.whateverthisaddressis.com).
    I'd like to know if anyone has a code out there to where php
    can find
    text with a
    http:// or www. and change it into a link
    automatically. I
    know there's many out there, but I don't have a clue what I'm
    looking at
    and where to put it.
    Any help would be greatly appreciated!
    Toad78

    You might find something here:
    http://ca3.php.net/preg_replace

  • Regular expressions for URLs to match extensions

    I am working on a simple method that will assign a specific extension
    (e.g. ".jsp", ".php", ".cfm", etc.) to the end of a URL if it doesn't
    find anything marking a valid extension, however, I do not want to add
    an extension if one is found.
    Consider my code:
    import java.util.regex.Pattern;
    public static final String urlEndSlashPattern = "/?";
    public static final String urlQSPattern = "\\??([a-zA-Z0-9\\-_\\.]
    +=[^&]*&?)*";
    public static final String urlAnchorPattern = "#[^#]*$";
    public static void addExtToUrl(String url, String myExt, String[]
    exts) {
       StringBuffer sb = new StringBuffer();
       boolean hasExt = false;
       for (int i = 0; i < exts.length; i++) {
    sb.append(".").append(exts).append(urlEndSlashPattern).append(urlQSPatte�rn).append(urlAnchorPattern);
    if (Pattern.matches(sb.toString(), url)) {
    hasExt = true;
    sb = new StringBuffer();
    if (!hasExt) {
    url += "." + myExt;
    The issue I want to bring up is the regular expression pattern I'm
    using appears to fail.  I want to check and see if the URL I provide
    ends with a valid extension, followed by optional "/" or a query
    string or an anchor or any combination of these.
    Like say if I have
    http://www.blah.com/index.html
    Then don't add the ".jsp" extension
    But if I have
    http://www.blah.com/registration/
    Then I *want* to add the ".jsp" extension:
    http://www.blah.com/registration.jsp
    Or if I have:
    http://www.blah.com/registration/?foo=bar#baz
    Then it needs to change to
    http://www.blah.com/registration.jsp?foo=bar#baz
    But if I have
    http://www.blah.com/registration/index.php?foo=bar#baz
    Then I do *not* add the ".jsp" extension.
    Hope that makes sense now.  Bottom line is that the pattern above
    doesn't seem to work.  Ideas?
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Ok, just for fun, let's try it.
    URL: http://www.blah.com/?bar=baz#anchor
    Absolutely valid URL and something possible (remember, Balus, this is from a database entry, thus, it can be anything at all!)
    Let's split onto the last /
    Your last entry will be
    ?bar=baz#anchor
    So if I re-insert the .jsp that it would not find I get
    http://www.blah.com/.jsp?bar=baz#anchor
    INVALID URL
    Now let's try this one, BalusC:
    http://www.blah.com/index.jsp?forwardURL=http://www.wee.com/gotcha_balus/
    Now we split according to the ... last /
    http://www.blah.com/index.jsp?forwardURL=http://www.wee.com/gotcha_balus.jsp
    Valid URL, but possibly wrong when the query string value for "forwardURL" is read, thus, making the URL ultimately wrong.
    Two examples that show that splitting by the last / can't work here.

  • URL paths and regular expressions in ASDM

    Some background info - I've recently switched to an ASA 5510 on 8.4(3) coming from a Checkpoint NGX platform (let's say fairly quickly and without much warning ). I have a couple questions and they're kind of similar so I'll post them up. I've read docs about regex and creating them both via command line and ASDM, but the examples always seem to include info I don't need or honestly something I don't understand yet (mainly related to defining class\inspect maps). If someone could provide a simple example of how to do these in ASDM that would help a lot in understanding how regular expressions are properly configured. So here we go.
    I know this is basic but I need to make sure I understand this properly - I have a single web server (so this won't be a global policy) where I need to allow access to a specific URL path\file and that's it. So we'll call it \test\testfile.doc. Any other access to any other path should be dropped. What's the best way to do this in ASDM (6.4)? I think if I saw a basic example for this I could figure out next few questions but I'll post them as well just in case.
    I have another single public web server (again this won't be a global policy) where I'd like to specify blocking file types, like .php, .exe., etc... again a basic example would be great.
    Lastly, and this is kind of related, but we have a single office/domain and sometimes we get spam from forged addresses appearing to be from our domain. On Checkpoint I used to use its built-in SMTP security server and could define if it received mail from *@mydomain.com to drop it because we would never receive mail externally from our own domain name. I saw something similar with ESMTP in ASDM and it looks kind of like how you set up the URL access mentioned above. Can I configure this in ASDM as well, and if so how?
    TIA for your help,
    Jordan

    /bump

  • Regular expressions in ActionScript??

    I have been looking at the Adobe publication Programming Action Script (pdf) and it
    specifies ECMA-262 3rd edition specification. But the specification don't seem to
    state exactly what type of regular expression engine and version is used.
    Is it POSIX, or PERL compatible regular expressions (or both)?
    I have read and used the classic O'Reilly text Mastering Regular Expressions
    and coded regular expressions in javascript/php/etc (anywhere regular expressions
    could be use, Apache configuration file, other server config files, etc etc etc)
    There is a difference in the type of engine used, where as performance is
    concerned, as well as the range of syntax valid in a particular implementation.
    Thank You
    JK

    http://www.regular-expressions.info/javascript.html

  • Regular expressions in eclipse

    am trying to filter out some search results in eclipse with regular expressions, but am not having any luck. I am trying to find all jsp pages that contain html:text tags that DON'T have a maxlength attribute.
    I have tried this, but it doesn't seem to work:
    html:text .*[^m][^a][^x][^l|L][^e][^n][^g][^t][^h]How do you specify to NOT match an entire string (like maxlength, for example) while still matching another string (like html:text) in the same regexp?
    Thanks in advance.

    "[^>m]++" matches one or more of anything that's not '>' or 'm', which is always safe. If that fails (meaning a '>' or 'm' was seen), the second alternative tries to match an 'm' unless it's the beginning of "maxlength" (it could actually be the middle of "foobarmaxlength", but I'm assuming that won't happen). The whole alternation is in a group controlled by an asterisk, so it will keep cycling until either '>' or "maxlength" is seen. If it's "maxlength" rather than '>' that stops the loop, the regex fails.
    I was assuming that '>' wouldn't appear inside a tag. (It actually can, even in HTML, if it's enclosed in quotes, but nobody ever seems to do that. JSP, of course, is another story.) I think the simplest way to fix this regex is to add another alternative for quoted values:  <html:text\b([^>"m]++|"[^"]*+"|m(?!axlength))*+>BTW, it's important to use possessive quantifiers (++, +, etc.) in a pattern like this, where the general form is (X)*. Otherwise, you could get into a runaway-backtracking scenario where the regex takes forever to decide no match is possible.

  • BUG?? Syntax Highlighting Regular Expressions

    I'm working on a rather long regular expression in
    dreamweaver code view. It has about 200+ characters in it.
    I wrote it in another application and copied it over for use
    in js, and it wouldn't highlight correctly (sort of like when you
    leave off quote on a string). Naturally I thought I screwed up my
    regexp or forgot to escape a character or something so I went
    through it re-writing it and checking everything but it was
    correct. I saved the page and ran it in the browser and sure enough
    it worked.
    So I started typing the regexp from scratch this time in
    dreamweaver to see when it stopped highlighting correctly. It
    stopped at exactly 100 characters including opening and closing
    forward slashes. I tried writing another exp this time filled with
    just one letter. Again 100 characters exactly - not one more.
    Example:
    var reg1 =
    /ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss ssssssssss/
    var reg2 =
    /ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss sssssssssss/
    reg1 will highlight correctly, while reg2 won't.
    Is this a bug or am I missing something? The highlight rule
    (in Configuration\CodeColoring\CodeColoring.xml) is
    (\s*/\e*\\/
    -or-
    =\s*/ \e*\\ /
    There seems to be no limitation to length there.
    While this is not a huge deal, I might as was well be coding
    in notepad (or my other script editors which highlight this
    correctly) because the highlighting is worthless from this point
    on.
    I could make these strings instead of literals but I have a
    lot of these long expressions and would rather not go through them
    and escape all of my back slashes (there are tons) as well as
    quotes - and make them more un-maintainable as they already are.
    Anyone have this problem? Or a solution to it?

    random_acts wrote:
    > I'm working on a rather long regular expression in
    dreamweaver code view. It
    > has about 200+ characters in it.
    I have never written a regex as long as that, but was
    fascinated by your
    question, so attempted to replicate your problem.
    I gave up at 614 characters, but the syntax coloring didn't.
    I suggest
    that you submit a bug report with the details of your actual
    code:
    http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
    David Powers
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    http://foundationphp.com/

  • JUnit - Regular Expressions and all that Jazz

    I can't help you with the JMeter-specific stuff, but your regex has a couple of regex metacharacters that need to be escaped. Also, the template should refer to group #1, becuase that's where the actual id number is matched.Reg Exp: <a href="appointmentDetailsPDA\.jsp\?id=(\d+)&
    Template: $1$[/pre                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hello, FD-san
    I�ve tried using a Regular Expression Extractor in
    JMeter, with the following parameters, but this does
    not seem to work:
    Ref Name: ${appointment_id}
    Reg Exp: <a
    href="appointmentDetailsPDA.jsp?id=([\d]*)\&
    Template: $0$
    Match No: -1
    Default: Specify the variable "appointment_id" without "$" and "{|}"
    Just
    Ref Name: appointment_id
    Reg Exp: <a href="appointmentDetailsPDA.jsp?id=([\d]*)\&
    Template: $1$ //$0$ refers to whatever the entire expression matches.
    Match No: 0 // stores rendom of matches
    Default:
    in this case you can refer to:
    appointment_id_gn - as to the n-th group of matches (n=0,1,2, ...)
    appointment_id_g - as to the last number of group (number of groups - 1)
    appointment_id - as to the group #1
    Good luck

  • Regular Expression Character Sets with Pattern and Matcher

    Hi,
    I am a little bit confused about a regular expressions I am writing, it works in other languages but not in Java.
    The regular expressions is to match LaTeX commands from a file, and is as follows:
    \\begin{command}([.|\n\r\s]*)\\end{command}
    This does not work in Java but does in PHP, C, etc...
    The part that is strange is the . character. If placed as .* it works but if placed as [.]* it doesnt. Does this mean that . cannot be placed in a character range in Java?
    Any help very much appreciated.
    Kind Regards
    Paul Bain

    In PHP it seems that the "." still works as a all character operator inside character classes.
    The regular expression posted did not work, but it does if I do:
    \\begin{command}((.|[\n\r\s])*)?\\end{command}
    Basically what I'm trying to match is a block of LaTeX, so the \\begin{command} and \\end{command} in LaTeX, not regex, although the \\ is a single one in LaTeX. I basically want to match any block which starts with one of those and ends in the end command. so really the regular expression that counts is the bit in the middle, ((.|[\n\r\s])*)?
    Am I right it saying that the "?" will prevent the engine matching the first and last \\bein and \\end in the following example:
    \\begin{command}
    some stuff
    \\end{command}
    \\begin{command}
    some stuff
    \\end{command}

  • Regular Expressions - Removing a Timestamp?

    I have hundreds of plain HTML pages. I'd like to remove the
    timestamp from them, which looks like this:
    [19:45]
    I've tried using the wildcard feature, but the problem is is
    that I want the BRACKETS gone, as well. Unfortunately, I've only
    succeeded in removing either the last bracket (with the open
    bracket and time still intact) or all of my data completely. How
    can I successfully delete the varying times and their brackets
    without touching the rest of my data?

    In Find/Replace, with Use Regular Expression turned on:
    Find:
    \[\d\d?:\d\d?\]
    Replace:
    (leave it blank)
    E. Michael Brandt
    www.divahtml.com
    www.divahtml.com/products/scripts_dreamweaver_extensions.php
    Standards-compliant scripts and Dreamweaver Extensions
    www.valleywebdesigns.com/vwd_Vdw.asp
    JustSo PictureWindow
    JustSo PhotoAlbum, et alia

  • Regular expression checker

    hi,
    i am new to regular expression. i would like to know if there is a tool to check regular expressions? the tool should based on the entered regular expression display the result.
    thanks

    import java.util.regex.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class JavaRegxTest extends JFrame implements ActionListener{
      JTextField regxInput, textInput;
      JButton doMatchButton, resetButton, exitButton;
      JTextArea resultsArea;
      public JavaRegxTest(){
        super("JavaRegxTest");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container cp = getContentPane();
        cp.setLayout(new GridLayout(2, 1));
        JPanel upPanel = new JPanel(new GridLayout(5, 1));
        upPanel.add(new JLabel("regular expression:   "));
        upPanel.add(regxInput = new JTextField(50));
        upPanel.add(new JLabel("sample text:          "));
        upPanel.add(textInput = new JTextField(50));
        JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
        buttonPanel.add(resetButton = new JButton("RESET"));
        buttonPanel.add(doMatchButton = new JButton("MATCH"));
        buttonPanel.add(exitButton = new JButton("EXIT"));
        upPanel.add(buttonPanel);
        resetButton.addActionListener(this);
        doMatchButton.addActionListener(this);
        exitButton.addActionListener(this);
        resultsArea = new JTextArea(20, 60);
        resultsArea.setEditable(false);
        JScrollPane jsp = new JScrollPane(resultsArea);
        cp.add(upPanel);
        cp.add(jsp);
        setSize(550, 700);
        setVisible(true);
      public void actionPerformed(ActionEvent e){
        JButton btn = (JButton)(e.getSource());
        if (btn == exitButton){
          System.exit(0);
        else if (btn == resetButton){
          reset();
        else if (btn == doMatchButton){
          doMatch();
      /* clear text */
      void reset(){
        regxInput.setText("");
        textInput.setText("");
        resultsArea.setText("");
      /* display match results */
      void doMatch(){
        resultsArea.setText(resultsArea.getText() + "REGX=" + regxInput.getText()
         + "\n" + "TEXT=" + textInput.getText() + "\n");
        try{
          Pattern pat = Pattern.compile(regxInput.getText());
          String sampleText = textInput.getText();
          Matcher mat = pat.matcher(sampleText);
          int gc = mat.groupCount();
          for (int i = 0; i <= gc; ++i){ //for each capture group
            resultsArea.setText(resultsArea.getText()
             + "GROUP" + i + " : \n"); //GROUP0 == whole match
            while (mat.find()){ //display every matched parts
              resultsArea.setText(resultsArea.getText()
               + " " + mat.group(i) + "\n");
            mat.reset(sampleText); //go to next group
        catch(Exception e){
          resultsArea.setText(e.toString());
      public static void main(String[] args){
        JavaRegxTest jrt = new JavaRegxTest();
    }

  • Do J2ME support Regular Expressions?

    If yes, how can i do that
    i want to get a html page by the j2me
    and use Regular Expressions to get all link from it (eg. http://yahoo.com/123.php )

    you can write your own code to do it parsing the text using a blank space to separate words, then analize them. I guess sun wont support regular expressions sooner but you can code it if needed.

  • Regular expression​.vi doesn't work correctly

    I try to parse the output from "Flatten To XML" using "Find Regular Expression" but I get unexpected results.
    Input: "<LvVariant><Name>myName</Name><Cluster>...</Clust​er></LvVariant>"
    Regular expression: "<(.+)><Name>(\w+)</Name>(.+)</\1>"
    Expected result: match1 = "LvVariant", match2 = "myName", match3 = "<Cluster>...</Cluster>", total match = input, before match = empty, after match = empty.
    LabVIEW's result: before match = input, all other output strings are empty.
    I checked the expression with other programming languages like PHP and Delphi. There it works fine, but not in LabVIEW. I think, there is a bug at the "Find regular expression.vi".

    ralfc wrote:
    I try to parse the output from "Flatten To XML" using "Find Regular Expression" but I get unexpected results.
    Input: "<LvVariant><Name>myName</Name><Cluster>...</Clust​er></LvVariant>"
    Regular expression: "<(.+)><Name>(\w+)</Name>(.+)</\1>"
    Expected result: match1 = "LvVariant", match2 = "myName", match3 = "<Cluster>...</Cluster>", total match = input, before match = empty, after match = empty.
    LabVIEW's result: before match = input, all other output strings are empty.
    I checked the expression with other programming languages like PHP and Delphi. There it works fine, but not in LabVIEW. I think, there is a bug at the "Find regular expression.vi".
    You are not using the Match Regular Expression correctly, try this:
    You need to expand the bottom of the vi to get the captured groups.
    Ben64

Maybe you are looking for

  • ITunes thinks that my iPad was never set up

    I recently got a retina display iPad. I set this up out of the box, using the iPad's quick start, product registration, etc. This iPad -- which is fully set up and functional -- will not successfully interface with iTunes. Attempting to sync the iPad

  • Trying to configure wifi throughout a large home

    I have a large home that has an upstairs, basement, and studio in the backyard. I need to set up wifi throughout the whole house and to the studio. Currently there are Ethernet connections in 7 locations of the house including 1 in the studio. There

  • Convert a String to java.sql.Date Format

    Hi, I am having a String of containing date in the format 'dd/mm/yyyy' OR 'dd-MMM-YYYY' OR 'mm-dd-yyyy' format. I need to convert the string to java.sql.Date object so that I can perform a query the database for the date field. Can any one suggest me

  • Apps won't stay in folder

    I now have 3 APPs that won't stay in their folders after sync. I download, move from page 2 into a folder and all is well. Then when I sync, they are moved to pg 2 again. Whats up with that?

  • My Mac won't start!

    I just bought my first Macbook not even 24 hours ago and I had it started up and it was working.  I left my house with it "sleeping" and returned a few hours later and it will not startup?  Thanks in advance