Pattern and Regular Expression problem

Hi all!
I have trouble with constructing a pattern.
Consider the following:
import java.util.regex.*;
public class Parser {
public Parser() {
String pattern = "<i18n:message(.*)/>";
String myline = "<INPUT type=\"button\" name=\"cancel\" value='<i18n:message key=\"EXP.EP.EPDATES.CANCEL\"/>' class=\"normal08\" onClick=\"javascript:disableInput();document.panel_menu.submit();\"/>";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(myline);
while ( (m.find()) ) {
System.out.println(m.group());
public static void main(String[] args) {
new Parser();
How should I construct the pattern in order to extract from the string myline just the following sequence: <i18n:message key=\"EXP.EP.EPDATES.CANCEL\"/>
It seems that using the pattern I wrote, it continues the match until the last appearance of "/>", and I need to have the match done until the first appearance of "/>".
Thanks a lot.

No, modify it to (.*?).Hey, unky. Would you mind schooling me a bit here?
"<i18n:message(.*?)/>" right?
against "<i18n:message key=\"EXP.EP.EPDATES.CANCEL\"/>' class=\"normal08\" onClick=\"javascript:disableInput();document.panel_menu.submit();\"/>"
I think I understand, but would appreciate confirmation or correction.
.* is zero or more of anything. The ? makes it reluctant (also called lazy?).
So .* is compared against nothing, succeeds, and the regex moves on to the next character.
This doesn't match / so regex backtracks and tries to match .* against the space, which succeeds, but then / doesn't match against the k in key
So we backtrack, and reluctantly add the k to what .* matches.
We keep adding a character to .*'s match every time the next character isn't a /.
Eventually, .* matches everything up to and including the quote before the first />.
At this point, the / and > literals match, and we're done.
Yes?
And we needed to make it reluctant, else the .* would have started by matching as much of the string as it could, gobbling up all of it, and then backtracking to give the /> literals their match at the end of the string.
Yes?
Thanks!

Similar Messages

  • Find/replace and regular expression problem

    Hello, i'm using find and replace with a regular expression
    for the first time. I have it checkmarked and it's finding my text
    but it's missing (not highlighting) the ')' at the end of the line.
    Here's my code:
    [($[0-9]+<font size="-2">US</font>)]
    it's supposed to find everything inside the square brackets -
    but it misses the closing parenthesis after </font>. I need
    to find this string and replace with nothing to remove the string
    from any/all pages. Is there a reason why it's missing the closing
    parenthesis? I was actually able to add a few more parenthesis
    (e.g. "))))") before OR after the closing square bracket and it
    still found the original text minus the closing bracket and the
    extra parenthesis didn't prevent the text from being found.
    Any help is appreciated!
    James...

    WyattEA wrote:
    > Hello, i'm using find and replace with a regular express
    for the first time. I
    > have it checkmarked and it's finding my text but it's
    missing (not
    > highlighting) the ')' at the end of the line. Here's my
    code:
    >
    > [($[0-9]+<font size="-2">US</font>)]
    That's not how square brackets work
    Try:
    \(\$\d+<font size="-2">US</font>\)
    A left parens, followed by the dollar sign, followed by at
    least one
    digit, followed by <font size="-2">US</font>,
    followed by a right parens.
    Mick
    >
    > it's supposed to find everything inside the square
    brackets - but it misses
    > the closing parenthesis after </font>. I need to
    find this string and replace
    > with nothing to remove the string from any/all pages. Is
    there a reason why
    > it's missing the closing parenthesis? I was actually
    able to add a few more
    > parenthesis (e.g. "))))") before OR after the closing
    square bracket and it
    > still found the original text minus the closing bracket
    and the extra
    > parenthesis didn't prevent the text from being found.
    >
    > Any help is appreciated!
    >
    > James...
    >

  • Patterns and Regular Expressions

    HI
    I am trying to search a string for words and return the count
    word : are
    String: are , we care about this.
    i get back count 2. It counts are and also care.
    but the count should be one.
    How can i limit the matcher to find only 'are' do a exact word match.
    this is the piece of code i am using.
    word = word + "\\b";
    Pattern p = Pattern.compile(word,Pattern.CASE_INSENSITIVE);
    //create a matcher with input string
    Matcher m = p.matcher(strOfFile);
    boolean result = m.find();
    while (result){
    intCount++;
    result = m.find();
    return intCount;
    Thanks

    Really doesn't work! Can't explain behavior since \A and \z are valid as anchors. I will check expression against Perl.
    word = "\\b" + word + "\\b"; // it works.

  • Match pattern: change regular expression search via front panel?

    Hello,
    I have an application that I am developing which is making use of Serial VISA.
    I am scanning the output of a serial port which is constantly spitting out a long string of data. 
    Data is being pulled from the string with several combinations of SCAN FROM STRING functions and MATCH PATTERN Functions.
    Question:
    How can I use a button or TEXT box on the FRONT PANEL that can change the MATCH PATTERN Functions Regular expression?  
    for example the string may spit out the following:
     Weight\s\s\s\s\s\s\s\s\s\s\s\s-0.00\slb\s\s\s\s\s\s-16\sbits\s+74.40\s\B0F\sCorrected\s\s\s\s\s\s-0.00\slb\s+0.999987\s%\s\r
    in this case the serial device is spitting out data in LB.
    It could be possible for the device to spit out data in KG ... thus I need to change the REGULAR EXPRESSION.
    Thank you for your time

    Hi,
    just a quick example.
    there are other way of doing this but I think the ComboBox is quite an easy one.
    hope this helps
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    ComboBox.vi ‏12 KB

  • Help with Java and Regular Expression

    Hello,
    I have one line of Java and regular expression that I got from the web :
    String[] opt;
    opt = line.split("\\s+(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
    If "line" contains :
    1 "Hello World"
    this code would give me :
    opt[0] : 1
    opt[1] : "Hello World"
    which is almost what I would like to do except for the double quotes. I wonder if someone could please help me change the regular expression so that it would return :
    opt[0] : 1
    opt[1] : Hello World
    Thank you and Best Regards,
    Chris

    It looks to me like this is a line from a space delimited file so you should use one of the free CSV parsers such as http://opencsv.sourceforge.net/ . These will handle the quotes properly even if a field actually contains a quote.

  • Url pattern tag and regular expression

    I am trying to set up my web.xml in Tomcat 4.1.3 container to go to one page if letters are entered in last part of url or go to another page if numbers are entered in the last part of a url.
    For example if here is how the url would be set up where the url will go to either the all numbers location or the non numbers location:
    Any number entry for last part of url which could be something like 343
    http://127.0.0.1:8080/theapp/pack/weburl/343
    Any non number entry for last part of url which could be something like abec
    http://127.0.0.1:8080/theapp/pack/weburl/abec
    My attempt below is not working because it doesnt seem to take the regular expressions. But if I manually put in letters such as: <url-pattern>/pack/weburl/ab</url-pattern> it would take me to the correct page. How does web.xml work with regular expressions inthe url-pattern tag??
    <servlet>
    <servlet-name>Number</servlet-name>
    <servlet-class>pack.Number</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Number</servlet-name>
    <url-pattern>/pack/weburl/\d*</url-pattern>
    </servlet-mapping>
    <servlet>
    <servlet-name>NotNumber</servlet-name>
    <servlet-class>pack.NotNumber</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>NotNumber</servlet-name>
    <url-pattern>/pack/weburl/[A-Za-z]</url-pattern>
    </servlet-mapping>

    Sorry, this pattern can't take regular expressions.
    Referring to the servlet spec section 11.2 which defines these mappings
    In the web application deployment descriptor, the following syntax is used to define
    mappings:
    � A string beginning with a �/� character and ending with a �/*� postfix is used
    for path mapping.
    � A string beginning with a �*.� prefix is used as an extension mapping.
    � A string containing only the �/� character indicates the "default" servlet of the
    application. In this case the servlet path is the request URI minus the context
    path and the path info is null.
    � All other strings are used for exact matches only.As an alternative, I would suggest that you match the request to a filter, and then use some logic based on request.getURI() to determine which resource to forward to from there.

  • [SOLVED]ZSH and regular expressions

    Hi
    I am getting into regular expressions and i have noticed that with my .zshrc file i have some problem. In bash this expression works:
    \^\[^#]
    but not also in zsh. I have also noted that regular expression works fine with other zshrc configurations found in archwiki (like grml) but i want to have my configuration. And i really can't find what command make a difference
    My .zshrc file is pulled from this site https://github.com/slashbeast/things/bl … s/DOTzshrc.
    # .zshrc
    # Author: Piotr Karbowski <[email protected]>
    # License: beerware.
    # Basic zsh config.
    umask 077
    ZDOTDIR=${ZDOTDIR:-${HOME}}
    ZSHDDIR="${HOME}/.config/zsh.d"
    HISTFILE="${ZDOTDIR}/.zsh_history"
    HISTSIZE='10000'
    SAVEHIST="${HISTSIZE}"
    export EDITOR="/usr/bin/vim"
    export TMP="$HOME/tmp"
    export TEMP="$TMP"
    export TMPDIR="$TMP"
    export TMPPREFIX="${TMPDIR}/zsh"
    if [ ! -d "${TMP}" ]; then mkdir "${TMP}"; fi
    if ! [[ "${PATH}" =~ "^${HOME}/bin" ]]; then
    export PATH="${HOME}/bin:${PATH}"
    fi
    # Not all servers have terminfo for rxvt-256color. :<
    if [ "${TERM}" = 'rxvt-256color' ] && ! [ -f '/usr/share/terminfo/r/rxvt-256color' ] && ! [ -f '/lib/terminfo/r/rxvt-256color' ] && ! [ -f "${HOME}/.terminfo/r/rxvt-256color" ]; then
    export TERM='rxvt-unicode'
    fi
    # Colors.
    red='\e[0;31m'
    RED='\e[1;31m'
    green='\e[0;32m'
    GREEN='\e[1;32m'
    yellow='\e[0;33m'
    YELLOW='\e[1;33m'
    blue='\e[0;34m'
    BLUE='\e[1;34m'
    purple='\e[0;35m'
    PURPLE='\e[1;35m'
    cyan='\e[0;36m'
    CYAN='\e[1;36m'
    NC='\e[0m'
    # Functions
    if [ -f '/etc/profile.d/prll.sh' ]; then
    . "/etc/profile.d/prll.sh"
    fi
    run_under_tmux() {
    # Run $1 under session or attach if such session already exist.
    # $2 is optional path, if no specified, will use $1 from $PATH.
    # If you need to pass extra variables, use $2 for it as in example below..
    # Example usage:
    # torrent() { run_under_tmux 'rtorrent' '/usr/local/rtorrent-git/bin/rtorrent'; }
    # mutt() { run_under_tmux 'mutt'; }
    # irc() { run_under_tmux 'irssi' "TERM='screen' command irssi"; }
    # There is a bug in linux's libevent...
    # export EVENT_NOEPOLL=1
    command -v tmux >/dev/null 2>&1 || return 1
    if [ -z "$1" ]; then return 1; fi
    local name="$1"
    if [ -n "$2" ]; then
    local file_path="$2"
    else
    local file_path="command ${name}"
    fi
    if tmux has-session -t "${name}" 2>/dev/null; then
    tmux attach -d -t "${name}"
    else
    tmux new-session -s "${name}" "${file_path}" \; set-option status \; set set-titles-string "${name} (tmux@${HOST})"
    fi
    t() { run_under_tmux rtorrent; }
    irc() { run_under_tmux irssi "TERM='screen' command irssi"; }
    over_ssh() {
    if [ -n "${SSH_CLIENT}" ]; then
    return 0
    else
    return 1
    fi
    reload () {
    exec "${SHELL}" "$@"
    confirm() {
    local answer
    echo -ne "zsh: sure you want to run '${YELLOW}$@${NC}' [yN]? "
    read -q answer
    echo
    if [[ "${answer}" =~ ^[Yy]$ ]]; then
    command "${=1}" "${=@:2}"
    else
    return 1
    fi
    confirm_wrapper() {
    if [ "$1" = '--root' ]; then
    local as_root='true'
    shift
    fi
    local runcommand="$1"; shift
    if [ "${as_root}" = 'true' ] && [ "${USER}" != 'root' ]; then
    runcommand="sudo ${runcommand}"
    fi
    confirm "${runcommand}" "$@"
    poweroff() { confirm_wrapper --root $0 "$@"; }
    reboot() { confirm_wrapper --root $0 "$@"; }
    hibernate() { confirm_wrapper --root $0 "$@"; }
    detox() {
    if [ "$#" -ge 1 ]; then
    confirm detox "$@"
    else
    command detox "$@"
    fi
    has() {
    local string="${1}"
    shift
    local element=''
    for element in "$@"; do
    if [ "${string}" = "${element}" ]; then
    return 0
    fi
    done
    return 1
    begin_with() {
    local string="${1}"
    shift
    local element=''
    for element in "$@"; do
    if [[ "${string}" =~ "^${element}" ]]; then
    return 0
    fi
    done
    return 1
    termtitle() {
    case "$TERM" in
    rxvt*|xterm|nxterm|gnome|screen|screen-*)
    local prompt_host="${(%):-%m}"
    local prompt_user="${(%):-%n}"
    local prompt_char="${(%):-%~}"
    case "$1" in
    precmd)
    printf '\e]0;%s@%s: %s\a' "${prompt_user}" "${prompt_host}" "${prompt_char}"
    preexec)
    printf '\e]0;%s [%s@%s: %s]\a' "$2" "${prompt_user}" "${prompt_host}" "${prompt_char}"
    esac
    esac
    git_check_if_worktree() {
    # This function intend to be only executed in chpwd().
    # Check if the current path is in git repo.
    # We would want stop this function, on some big git repos it can take some time to cd into.
    if [ -n "${skip_zsh_git}" ]; then
    git_pwd_is_worktree='false'
    return 1
    fi
    # The : separated list of paths where we will run check for git repo.
    # If not set, then we will do it only for /root and /home.
    if [ "${UID}" = '0' ]; then
    # running 'git' in repo changes owner of git's index files to root, skip prompt git magic if CWD=/home/*
    git_check_if_workdir_path="${git_check_if_workdir_path:-/root:/etc}"
    else
    git_check_if_workdir_path="${git_check_if_workdir_path:-/home}"
    git_check_if_workdir_path_exclude="${git_check_if_workdir_path_exclude:-${HOME}/_sshfs}"
    fi
    if begin_with "${PWD}" ${=git_check_if_workdir_path//:/ }; then
    if ! begin_with "${PWD}" ${=git_check_if_workdir_path_exclude//:/ }; then
    local git_pwd_is_worktree_match='true'
    else
    local git_pwd_is_worktree_match='false'
    fi
    fi
    if ! [ "${git_pwd_is_worktree_match}" = 'true' ]; then
    git_pwd_is_worktree='false'
    return 1
    fi
    # todo: Prevent checking for /.git or /home/.git, if PWD=/home or PWD=/ maybe...
    # damn annoying RBAC messages about Access denied there.
    if [ -d '.git' ] || [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" = 'true' ]; then
    git_pwd_is_worktree='true'
    git_worktree_is_bare="$(git config core.bare)"
    else
    unset git_branch git_worktree_is_bare
    git_pwd_is_worktree='false'
    fi
    git_branch() {
    git_branch="$(git symbolic-ref HEAD 2>/dev/null)"
    git_branch="${git_branch##*/}"
    git_branch="${git_branch:-no branch}"
    git_dirty() {
    if [ "${git_worktree_is_bare}" = 'false' ] && [ -n "$(git status --untracked-files='no' --porcelain)" ]; then
    git_dirty='%F{green}*'
    else
    unset git_dirty
    fi
    precmd() {
    # Set terminal title.
    termtitle precmd
    if [ "${git_pwd_is_worktree}" = 'true' ]; then
    git_branch
    git_dirty
    git_prompt=" %F{blue}[%F{253}${git_branch}${git_dirty}%F{blue}]"
    else
    unset git_prompt
    fi
    preexec() {
    # Set terminal title along with current executed command pass as second argument
    termtitle preexec "${(V)1}"
    chpwd() {
    git_check_if_worktree
    man() {
    if command -v vimmanpager >/dev/null 2>&1; then
    PAGER="vimmanpager" command man "$@"
    else
    command man "$@"
    fi
    # Are we running under grsecurity's RBAC?
    rbac_auth() {
    local auth_to_role='admin'
    if [ "${USER}" = 'root' ]; then
    if ! grep -qE '^RBAC:' "/proc/self/status" && command -v gradm > /dev/null 2>&1; then
    echo -e "\n${BLUE}*${NC} ${GREEN}RBAC${NC} Authorize to '${auth_to_role}' RBAC role."
    gradm -a "${auth_to_role}"
    fi
    fi
    #rbac_auth
    # Check if we started zsh in git worktree, useful with tmux when your new zsh may spawn in source dir.
    git_check_if_worktree
    if [ "${git_pwd_is_worktree}" = 'true' ]; then
    git_branch
    git_dirty
    git_prompt=" %F{blue}[%F{253}${git_branch}${git_dirty}%F{blue}]"
    else
    unset git_prompt
    fi
    # Le features!
    # extended globbing, awesome!
    setopt extendedGlob
    # zmv - a command for renaming files by means of shell patterns.
    autoload -U zmv
    # zargs, as an alternative to find -exec and xargs.
    autoload -U zargs
    # Turn on command substitution in the prompt (and parameter expansion and arithmetic expansion).
    setopt promptsubst
    # Control-x-e to open current line in $EDITOR, awesome when writting functions or editing multiline commands.
    autoload -U edit-command-line
    zle -N edit-command-line
    bindkey '^x^e' edit-command-line
    # Include user-specified configs.
    if [ ! -d "${ZSHDDIR}" ]; then
    mkdir -p "${ZSHDDIR}" && echo "# Put your user-specified config here." > "${ZSHDDIR}/example.zsh"
    fi
    for zshd in $(ls -A ${HOME}/.config/zsh.d/^*.(z)sh$); do
    . "${zshd}"
    done
    # Completion.
    autoload -Uz compinit
    compinit
    zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
    zstyle ':completion:*' completer _expand _complete _ignored _approximate
    zstyle ':completion:*' menu select=2
    zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
    zstyle ':completion::complete:*' use-cache 1
    zstyle ':completion:*:descriptions' format '%U%F{cyan}%d%f%u'
    # If running as root and nice >0, renice to 0.
    if [ "$USER" = 'root' ] && [ "$(cut -d ' ' -f 19 /proc/$$/stat)" -gt 0 ]; then
    renice -n 0 -p "$$" && echo "# Adjusted nice level for current shell to 0."
    fi
    # Fancy prompt.
    if over_ssh && [ -z "${TMUX}" ]; then
    prompt_is_ssh='%F{blue}[%F{red}SSH%F{blue}] '
    elif over_ssh; then
    prompt_is_ssh='%F{blue}[%F{253}SSH%F{blue}] '
    else
    unset prompt_is_ssh
    fi
    case $USER in
    root)
    PROMPT='%B%F{cyan}%m%k %(?..%F{blue}[%F{253}%?%F{blue}] )${prompt_is_ssh}%B%F{blue}%1~${git_prompt}%F{blue} %# %b%f%k'
    PROMPT='%B%F{blue}%n@%m%k %(?..%F{blue}[%F{253}%?%F{blue}] )${prompt_is_ssh}%B%F{cyan}%1~${git_prompt}%F{cyan} %# %b%f%k'
    esac
    # Ignore lines prefixed with '#'.
    setopt interactivecomments
    # Ignore duplicate in history.
    setopt hist_ignore_dups
    # Prevent record in history entry if preceding them with at least one space
    setopt hist_ignore_space
    # Nobody need flow control anymore. Troublesome feature.
    #stty -ixon
    setopt noflowcontrol
    # Fix for tmux on linux.
    case "$(uname -o)" in
    'GNU/Linux')
    export EVENT_NOEPOLL=1
    esac
    # Aliases
    alias cp='cp -iv'
    alias rcp='rsync -v --progress'
    alias rmv='rsync -v --progress --remove-source-files'
    alias mv='mv -iv'
    alias rm='rm -iv'
    alias rmdir='rmdir -v'
    alias ln='ln -v'
    alias chmod="chmod -c"
    alias chown="chown -c"
    if command -v colordiff > /dev/null 2>&1; then
    alias diff="colordiff -Nuar"
    else
    alias diff="diff -Nuar"
    fi
    alias grep='grep --colour=auto'
    alias egrep='egrep --colour=auto'
    alias ls='ls --color=auto --human-readable --group-directories-first --classify'
    # Keys.
    case $TERM in
    rxvt*|xterm*)
    bindkey "^[[7~" beginning-of-line #Home key
    bindkey "^[[8~" end-of-line #End key
    bindkey "^[[3~" delete-char #Del key
    bindkey "^[[A" history-beginning-search-backward #Up Arrow
    bindkey "^[[B" history-beginning-search-forward #Down Arrow
    bindkey "^[Oc" forward-word # control + right arrow
    bindkey "^[Od" backward-word # control + left arrow
    bindkey "^H" backward-kill-word # control + backspace
    bindkey "^[[3^" kill-word # control + delete
    linux)
    bindkey "^[[1~" beginning-of-line #Home key
    bindkey "^[[4~" end-of-line #End key
    bindkey "^[[3~" delete-char #Del key
    bindkey "^[[A" history-beginning-search-backward
    bindkey "^[[B" history-beginning-search-forward
    screen|screen-*)
    bindkey "^[[1~" beginning-of-line #Home key
    bindkey "^[[4~" end-of-line #End key
    bindkey "^[[3~" delete-char #Del key
    bindkey "^[[A" history-beginning-search-backward #Up Arrow
    bindkey "^[[B" history-beginning-search-forward #Down Arrow
    bindkey "^[Oc" forward-word # control + right arrow
    bindkey "^[Od" backward-word # control + left arrow
    bindkey "^H" backward-kill-word # control + backspace
    bindkey "^[[3^" kill-word # control + delete
    esac
    bindkey "^R" history-incremental-pattern-search-backward
    bindkey "^S" history-incremental-pattern-search-forward
    if [ -f ~/.alert ]; then cat ~/.alert; fi
    Thanks for all the help.
    Last edited by Shark (2013-05-11 22:32:24)

    Raynman wrote:
    "This expression doesn't work", "It doesn't work" ...
    Could you try being a bit more specific?
    Firstly, i am sorry i didn't post the output. I should have know better.
    Secondly, chill out.
    I have used above regex with grep command. Output from terminal is:
    zsh: bad pattern: ^[^#]
    In bash it works perfectly.
    If i issue "setopt re_match_pcre" i have the same ouput as above.
    EDIT: If i issue "unsetopt no_match" it actually works but i have to change the regex from "\^\[^#]" to "\^[^#]" otherwise i get the same output as above. In bash both options work.
    Last edited by Shark (2013-05-11 22:07:21)

  • Simple regular expression problem

    Hello,
    I need help with regular expressions. I have a situation when I need to get data from one table to another and I think my problem can be solved using REG EXP, but I don't know how to use them properly.
    I need to seperate varchar2 fileld whcih is basically number/number into 2 seperate number fields
    CREATE TABLE tst (CODE VARCHAR2(10));
    INSERT INTO tst VALUES('10/15');
    INSERT INTO tst VALUES('13/12');
    INSERT INTO tst VALUES('30');
    INSERT INTO tst VALUES('15');
    CREATE TABLE tst2 (po NUMBER, co NUMBER); I need to get code into co and po columns. I think result should look something like this, but:
    INSERT INTO tst2
    SELECT regexp_substr(CODE 'something here to get the number before /') AS po,
           regexpr_substr(CODE 'something here to get number after') AS co
    FROM tst;   Any help appreciated

    Hi Blu,
    Yes, I have tested with "0" in the figure (like 10/20 30/40). And it worked that time and then I replied. :) :)
    But Still it has a problem in pattern and rectified it below.
    Like :-
    SQL> select regexp_substr('10/40','[^/][0 9]',1,2) DD from dual;
    DD
    40
    But if I (The way you test) use a non zero value like 43 ; below query will not return 43.
    SQL> select regexp_substr('15/43','[^/][0 9]',1,2) DD from dual;
    DD
    My pattern has a slight mistake("-" missing between 0 and 9) and I changed and retested . Correct pattern - '[^/][0-9]' and now it will return 43..
    SQL> select regexp_substr('15/43','[^/][0-9]',1,2) dd from dual ;
    DD
    43this '[^/]+' pattern also works fine.
    Thank you for pointing out Blu; as I came to know lot more about patterns.
    Regards,
    Ashutosh

  • Pattern matching regular expressions

    I'm attempting to determine if a string matches a pattern of containing less than 100 alphanumeric characters a-z or 0-9 case insensitive. So my regular expression string looks like:
    "^[a-zA-Z0-9]{0,100}$"And I use something like...
    Pattern pattern = Pattern.compile( regexString );I'd like to modify my regex string to include the email 'at' symbol "@". So that the at symbol will be allowed. But my understanding of regex is very limited. How do I include an "or at symbol" in my regex expression?
    Thanks for your help.

    * Code by sabre150
    private static final Pattern emailMatcher;
        static
            // Build up the regular expression according to RFC821
            // http://www.ietf.org/rfc/rfc0821.txt
            // <x> ::= any one of the 128 ASCII characters (no exceptions)
            String x_ = "\u0000-\u007f";
            // <special> ::= "<" | ">" | "(" | ")" | "[" | "]" | "\" | "."
            //              | "," | ";" | ":" | "@"  """ | the control
            //              characters (ASCII codes 0 through 31 inclusive and
            //              127)
            String special_ = "<>()\\[\\]\\\\\\.,;:@\"\u0000-\u001f\u007f";
            // <c> ::= any one of the 128 ASCII characters, but not any
            //             <special> or <SP>
            String c_ = "[" + x_ + "&&" + "[^" + special_ + "]&&[^ ]]";
            // <char> ::= <c> | "\" <x>
            String char_ = "(?:" + c_ + "|\\\\[" + x_ + "])";
            // <string> ::= <char> | <char> <string>
            String string_ = char_ + "+";
            // <dot-string> ::= <string> | <string> "." <dot-string>
            String dot_string_ = string_ + "(?:\\." + string_ + ")*";
            // <q> ::= any one of the 128 ASCII characters except <CR>,
            //               <LF>, quote ("), or backslash (\)
            String q_ = "["+x_+"$$[^\r\n\"\\\\]]";
            // <qtext> ::=  "\" <x> | "\" <x> <qtext> | <q> | <q> <qtext>
            String qtext_ = "(?:\\\\[" + x_ + "]|" + q_ + ")+";
            // <quoted-string> ::=  """ <qtext> """
            String quoted_string_ = "\"" + qtext_ + "\"";
            // <local-part> ::= <dot-string> | <quoted-string>
            String local_part_ = "(?:(?:" + dot_string_ + ")|(?:" + quoted_string_ + "))";
            // <a> ::= any one of the 52 alphabetic characters A through Z
            //              in upper case and a through z in lower case
            String a_ = "[a-zA-Z]";
            // <d> ::= any one of the ten digits 0 through 9
            String d_ = "[0-9]";
            // <let-dig> ::= <a> | <d>
            String let_dig_ = "[" + a_ + d_ + "]";
            // <let-dig-hyp> ::= <a> | <d> | "-"
            String let_dig_hyp_ = "[-" + a_ + d_ + "]";
            // <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
            // String ldh_str_ = let_dig_hyp_ + "+";
            // RFC821 looks wrong since the production "<name> ::= <a> <ldh-str> <let-dig>"
            // forces a name to have at least 3 characters and country codes such as
            // uk,ca etc would be illegal! I shall change this to make the
            // second term of <name> optional by make a zero length ldh-str allowable.
            String ldh_str_ = let_dig_hyp_ + "*";
            // <name> ::= <a> <ldh-str> <let-dig>
            String name_ = "(?:" + a_ + ldh_str_ + let_dig_ + ")";
            // <number> ::= <d> | <d> <number>
            String number_ = d_ + "+";
            // <snum> ::= one, two, or three digits representing a decimal
            //              integer value in the range 0 through 255
            String snum_ = "(?:[01]?[0-9]{2}|2[0-4][0-9]|25[0-5])";
            // <dotnum> ::= <snum> "." <snum> "." <snum> "." <snum>
            String dotnum_ = snum_ + "(?:\\." + snum_ + "){3}"; // + Dotted quad
            // <element> ::= <name> | "#" <number> | "[" <dotnum> "]"
            String element_ = "(?:" + name_ + "|#" + number_ + "|\\[" + dotnum_ + "\\])";
            // <domain> ::=  <element> | <element> "." <domain>
            String domain_ = element_ + "(?:\\." + element_ + ")*";
            // <mailbox> ::= <local-part> "@" <domain>
            String mailbox_ = local_part_ + "@" + domain_;
            emailMatcher = Pattern.compile(mailbox_);
            System.out.println("Email address regex = " + emailMatcher);
        }Wow. Sheesh, sabre150 that's pretty impressive. I like it for two reasons. First it avoids some false negatives that I would have gotten using the regex I mentioned. Like, [email protected] is a valid email address which my regex pattern has rejected and yours accepts. It's unusual but it's valid. And second I like the way you have compartmentalized each rule so that changes, if any custom changes are desired, are easier to make. Like if I want to specifically aim for a particular domain for whatever reason. And you've commented it so that it is easier to read, for someone like myself who knows almost nothing about regex.
    Thanks, Good stuff!

  • Regular Expressions - Problem

    Hi @ all,
    I need a complicate regular expression, I don´t know.
    I have a big folder with many .htm pages (800-1000) and I have to do the following:
    http://www.domain.de/ab%32-xyz?myshop=123
    I have to delete the "ab%32-xyz", the problem is, that in this are, there could be every symbol, letter or number.
    So the area between "http://www.domain.de/" and "?myshop=123" (these 2 areas are everytime identical in all documents) shoud be deleted.
    Could everyone say me, how to do this with regular expressions in dreamweaver?
    Thanks,
    Felix
    P.S.: Sorry, my Engish is not so good, I´m from Germany

    Do you want to replace the random text with anything?
    If not, this is how you do it in DW:
    Make a backup of the folder you want to edit, just in case anything goes wrong
    Edit > Find and Replace
    In the Find and Replace dialog box, select Folder from the "Find in" drop-down menu, and select the folder you want to work with.
    Select Source Code from the Search drop-down menu.
    Put the following code in the Find text area:
    (http://www\.domain\.de/)[^?]+(\?myshop=123)
    Put the following code in the Replace text area:
    $1$2
    In Options, select the "Use regular expression" check box.
    Click Replace All. Dreamweaver will warn you that the operation cannot be undone in pages that aren't currently open. As long as you have made a backup, click OK to perform the operation.

  • ACE20 Module, webservices and regular expressions.

    Hello All,
    I am trying to loadbalance requests for webservices in a serverfarm. But for some reason, ACE20 module y not making matches on the requests.
    We have a serverfarm Prod1 with 2 real servers and another serverfarm named WSDL with other 2 real servers.
    The idea is the following, if we receive the following string, /App.WebService, the ACE should redirect it to serverfarm Prod1, but if it receives /App.WebService?wsdl, it should be redirected to WSDL.
    Request with string /App.WebService --------------> ServerFarm Prod1
    Request with string /App.WebService?wsdl -----> ServerFarm WSDL
    We use regular expression in L7 class maps to make the loadbalance to happen.
    class-map type http loadbalance match-all APP.WEBSERVICES-L7-SLB
      2 match http url /App\.WebService\?wsdl
    class-map type http loadbalance match-all APP-L7-SLB
      2 match http url /App\.WebService
    policy-map type loadbalance first-match L7_SLB-POLICY
      class APP.WEBSERVICES-L7-SLB
        serverfarm WSDL
      class APP-L7-SLB
        serverfarm Prod1
      class L4_SLB_DATAPOWER(9050)
        loadbalance vip inservice
        loadbalance policy L7_SLB-POLICY
        loadbalance vip icmp-reply
        appl-parameter http advanced-options HTTP_PARAM
        ssl-proxy server wildcard.test.org
        connection advanced-options TCP_PARAM
    But the ACE20 Module seems to be removing the ?wsdl from the URL and only the class-map called APP-L7-SLB is being matched.
    Any comments or suggestions on why this could be happening?
    Thanks in advance,
    Fernando

    Hello Kanwal and all,
    Finally, after reading and reading I found a fix to this problem. Seems that the HTTP protocol uses the question mark (?) character as a delimiter for data appended to the URL. So, if you get the following:
    www.test1.org/App.WebService?wsdl
    If you configured a L7 class map to parse the URL, it will only parse until the question mark (?).
    So you need to create a PARAMETER-MAP changing the URL delimiter start. Here is an example:
    parameter-map type http HTTP_PARAMETER_MAP_WSDL
      persistence-rebalance strict
      set secondary-cookie-delimiters ;!@?
      set secondary-cookie-start ;
    I used the semicolon ( ; ) as delimiter.
    Hope this helps.
    Fernando

  • Interesting Regular Expression Problem

    Hi - I am fairly new to Java, but have some reg exp experience.
    Basically, I would like a regular expression to strip elements out of a text format. The elements are delimited by curly braces, very similar to Java. The problem is that the elements may contain other elements - the format is hierarchical. I need to extract the whole element, including its children.
    For example, I need to extract the B element from
    [A]
    a1     1
    a2     2
    b1     1
    b2     2
    [C]{
    c1     1
    c2     2}
    [C]{
    c1     3
    c2     4}}
    and the answer should be
    b1     1
    b2     2
    [C]{
    c1     1
    c2     2}
    [C]{
    c1     3
    c2     4}}
    The nature of the format is not fixed - I won't know how many child elements the B element contains.
    Can this be done using regular expressions, or do I have to write a custom string handling function?
    Thanks for any help.
    Mark

    :-) And I still don't understand it!It's quite easy though ;-) Suppose a word w is generated by some grammar.
    If this grammar is regular you can write word w as xyz where y is not the empty
    word and |x| < p. if w is generated by a regular grammar then xy^nz
    (n occurrences of y) can also be generated by the same grammar. That's
    the 'pumping' giggle part.
    Now suppose the language of nested parentheses is a regular language.
    All you have to do is find a word w = xyz where xy^nz is not part of the language.
    Let w= ((())) and x= ((, y= ( and z= ))), obviously xy^nz is not a properly nested
    parentheses word for n > 1. Note that every generated word in that language,
    long enough has to have that value p, where xy^nz |x| < p and xy^nz in the language.
    The pumping lemma giggle for context free languages is almost the same:
    you have to find two positions where the pumping fails/succeeds.
    kind regards,
    Jos (huhuh, he said 'pumping' ;-)

  • PrintWriter issue with Directory Traversal and Regular Expression

    This is a follow up to my previous question on the forum. I am developing a program traverses the hard drive for information. If it finds the said information in any of the file (based on the regular expression wriiten) it must print the output into the file. Currently I am able to traverse the harddrive perfectly, the regular expression and the search is perfect and when I print the output into the local console, I am able to derive perfect results. But when I use the PrintWriter to write the output into the flight, it writes NOTHING into the file. I have been scouring all over the Internet for an answer, but havent been able to find. Would highly appreciate if someone can tell me what I am doing wrong and provide some guidance on how to get it right.
    public class myClass{
        BufferedReader br;
        String pcv;
        Pattern scPattern = Pattern.compile("Some regular expression");
        Matcher match = null;
        Pattern newPattern = Pattern.compile("Some regular expression");
        Matcher newMatch = null;
        String mvCheckVal;
        Matcher mvMatch;
        PrintWriter pw;
        void recursiveMethod(File dir) throws Exception {
                pw = new PrintWriter(new FileWriter("outputFile.txt"));
                pw.println("Opening pw stream.....");
                File[] files = dir.listFiles();
                String[] fileList = dir.list();
                for (int i = 0;i < files.length; i++) {
                    if (files.isDirectory()) {
    continue;
    } else if (files[i].isFile()) {
    br = new BufferedReader(new FileReader(files[i]));
    pw.println("BR is opening....");
    String line;
    while((line = br.readLine()) != null) {
    match = scPattern.matcher(line);
    if (match.find()) {
    pcv = line.substring(match.start(), match.end());
    System.out.println("Match: " + pcv + " Context: " + match.replaceFirst(pcv)); //This is working perfectly
    pw.println("Match: " + pcv + " Context: " + match.replaceFirst(pcv)); //This does not print anything at all
    System.out.println("Files: " + files[i]);
    System.out.println("");
    pw.println(" Files: " + files[i]);
    pw.println("");
    System.out.println("Closing I/O....");
    br.close();
    pw.close();
    public static void main(String[]args) throws Exception {
    File dir = new File("C:/");
    myNewClass acf = new myNewClass();
    acf.myClass(dir);

    @ejp
    I am afraid that it is not working. Can you please tell me what I doing wrong.
    void myMethod(File dir) throws Exception {
                bw = new BufferedWriter(new FileWriter("outputFile.txt"));
                File[] files = dir.listFiles();
                String[] fileList = dir.list();
                for (int i = 0;i < files.length; i++) {
                    if (files.isDirectory()) {
    myMethod(files[i]);
    } else if (files[i].isFile()) {
    br = new BufferedReader(new FileReader(files[i]));
    String line;
    while((line = br.readLine()) != null) {
    match = scPattern.matcher(line);
    if (match.find()) {
    pcv = line.substring(match.start(), match.end());
    System.out.println("Match: " + pcv + " Context: " + match.replaceFirst(pcv));
    bw.write("Match: " + pcv + " Context: " + match.replaceFirst(pcv));
    br.close();
    bw.write("Files: " + files[i]);
    bw.write("");
    bw.close();
    public static void main(String[]args) throws Exception {
    File dir = new File("C:/");
    myClass acf = new myClass();
    acf.myMethod(dir);

  • [solved] Need a little help with sed and regular expressions

    Hello!
    I am shure this is something easy for most of you
    I want to make a script, which converts filenames of my ripped MP3s (replaces '_' with spaces, removes leading track numbers...)
    But I have some problems:
    j=$(echo $j | sed 's/_\+/ /g')
    j=$(echo $j | sed 's/^[0-9]{0,3}//g')
    j=$(echo $j | sed 's/[^ ]-[^ ]/ - /g')
    j=$(echo $j | sed 's/_\+/ /g') << this is working fine (converts all "_" to spaces)
    j=$(echo $j | sed 's/^[0-9]{0,3}//g') << is NOT working, why??
    For Example in "01-somebody_feat_someone-somemusic.mp3" the leading "01" number is NOT being removed..
    j=$(echo $j | sed 's/[^ ]-[^ ]/ - /g') << how can I insert spaces before and after the "-"?
    So that "someone-somemusic" becomes "someone - somemusic" (but only where "-" is surrounded by letters)
    Last edited by cyberius (2011-07-27 18:50:54)

    For sed, you must escape { and } to use them as you want (just slap a \ before them).
    For the last expression, capture the letter before/after the dash -- use \( and \) -- and then substitute it for something like "\1 -" and then "- \1". You'll want to split this into two pieces, one for the front and one for the back so you can get "somemusic -someband" the way you want without a bunch of cases.
    Edit: Or, you could just do a replace for "-" to be " - " and then have another expression to reduce spaces. I see you've used \+ before, so I'm guessing you can figure that out
    Also, sed has the -e switch so you can do multiple different expressions with one invocation.
    Also (also), have you looked into something like Picard with automatic track renaming? You can even customize how they are renamed.
    Edit (2): Also^3, check out prename. There are different versions, ones which use PCRE and ones that use other standards, but it is for renaming files based on regular expressions, which is what you're doing. In any case, you might want to put you script into the User made scripts thread when you feel more comfortable and get some more critiquing, if you're interested.
    Last edited by jac (2011-07-26 23:13:27)

  • 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

Maybe you are looking for

  • After choosing a blank template in PAGES, i am unable to type in the main body of the docs. I have to open a text box to type. Pls help

    Hi all, need help here. I just face this problem today. When i click the pages icon and after choosing a blank template, i am unable to type anything in the document. All icons in the format bar at the top cannot be clicked (font, font size etc). I w

  • Canon Pixma MG7120 and OS 10.9.1

    I am in search of a new printer that is compatible with OS X Mavericks.  Been looking at the Canon Pixma MG7120 but hard to find on amazon or canon website if this printer is fully compatible 10.9.1.  Anyone know from firsthand experience or otherwis

  • I feel stupid asking this but.....

    Hi feel real stupid asking these questions but here goes: - What is the 'Option' key on the keybord? If i want use a hash character how do i do that? when i sign in on my mac i have to type in my password but if i type it wrong it takes me to a windo

  • How to mirror ipad screen on desktop?

    Hello, I often do web meeting from my desktop and want to get my ipad screen on my desktop. Is there any app that will display my ipad screen to desktop. My both the device are on diffrent network. Ipad is using 3g datacard and laptop is using office

  • LR Star Ratings into iPhoto?

    I routinely export a (relatively small) portion of my LR catalog as jpgs and import those into iPhoto ('08) for online sharing, syncing with iPod touch and a few other reasons. LR keywords move over just fine but I'm not able to get the star ratings