[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)

Similar Messages

  • 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.

  • [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

  • Question sql and regular expressions

    I am trying to write a query where a like with a regular % wont work.
    select <cols>
    from <tab>
    where col2 starts with 'SOME CHARACTERS' The field can have 0 or more empty spaces before there are more characters. However, I know what those characters are. How do I do 0 or more characters?
    select mycols
    from myemptable
    where empname like 'JO%JO'There could be 0 or more empty spaces between JO and JO, but the next character is 'JO' . This is a general case. So it could be something else.
    so % won't work. since i could get back 'JO HA JO' which I dont want.

    Regular expressions where introduced with Unix in 1973.
    It shouldn't be difficult to find online resources.
    You seem to belong to the big class of users in this forum who doesn't know how to use the Internet, or find that to demanding.
    The solution can of course be found in 5 minutes, of 2 to start my database especially for you at almost midnight.
    with a as (select 'JO JO' col1 from dual
                  union
                   select 'JO    JO' col1 from dual
                   union
                  select 'JO HA JO' col1 from dual
                  union all
                  select 'JO  JO BLEH' from dual)
       select * from a where regexp_like(col1,'^JO( +)JO.*$')
    You find out what it means as exercise.
    Sybrand Bakker
    Senior Oracle DBA

  • 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

  • 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);

  • 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...
    >

  • 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]Issue concerning regular expressions

    Perhaps the problem in it's entirety is a bit more involved that just regular expressions, but for a start, this small problem is what I need help with.
    In short, I have some data which can be in the of some text, an IP address or an URL.
    In case that it's URL, it will usually, if not always, be in the form of a base URL, with or without one or more subdomains.
    I need to strip away these sub domains so that only the base URL remain, thus:
    abc.def.ghi.com
    becomes
    ghi.com
    forgetting for the moment that some top level domains have two parts, it seems so easy, yes I cannot for the life of me figure out how to do it, using only the basic command line tool available such as sed, awk, and so on and so forth, and thus I hope that someone here can and will help me. It is of course also possible that the process is simply to involved that a simple command line will do, in which case I suppose a bahs or python script will have to do, but I really hope not. In any case I will appreciate any help and/or advise you can give me.
    Best regards.
    Last edited by zacariaz (2015-05-07 13:38:47)

    WorMzy wrote:
    Is this a homework exercise?
    What have you tried so far? It should be easy enough to accomplish using a combination of rev and cut, although I'm sure there are more elegant solutions using awk.
    Mod note: Moving to Newbie Corner
    I wish it were homework, but no.
    The rev idea is interesting, and I'll look into it, but as it is, an awk solution would be preferable, as this is only part of a larger issue, and I'd like to keep it as simple as possible. Also, as for topdomain with two parts, it's still somewhat involved.
    As for what I've tried, a lot as I only stopped and went to bed when I realized the sun was raising, but the main problem is that I don't really know how to attack the problem, and of course I'm not exactly a master of regular expressions.
    Anyway thanks.

  • JFormattedTextField Mask and regular expression

    Hi,
    I have to allow a user to enter numeric values only. The first 3 digits are mandatory, followed by a space, followed by a maximum of 20 digits,
    I am trying to use the regex formatter from Sun at
    http://java.sun.com/products/jfc/tsc/articles/reftf/
    Plus, I wanted to have a mask as well, so that the user does not have to type-in the space.
    So far, I haven't had any luck in getting to implement both.
    Any helps would be greatly appreciated.
    Thanks

    Hello,
    ... so that the users don't have to type-in the space?I don't see a solution with regular expressions for that, although I'm not an expert in that field. Let's take an example with a more "visible" character like "123-456", regex only checks, but doesn't display or jump over separator literals.
    Presently I can only see a solution in using a normal MaskFormatter
        MaskFormatter mf1;
        try
        { mf1 = new MaskFormatter("### #####");
        catch (ParseException e)
        JFormattedTextField tf = new JFormattedTextField();
        mf1.install(tf);If you install a field to a maskFormatter it doesn't oblige you to fully fill up the mask, as happens if doing a
    JFormattedTextField tf = new JFormattedTextField(mf1);
    This nicely jumps over the blank (or any other literal). However, you
    have to check whether at least three ciphers have been input. This could be done either in an Action- or Focus(Lost)Listener or by means of an InputVerifier.
    Greetings
    Joerg

  • [SOLVED] Zsh and the move to /usr/bin

    I've done everything in the article, and I have no unofficial packages.
    However, I do use zsh as my shell, so I thought I might as well ask before doing anything:
    Blog wrote:# pacman -Syu --ignore filesystem,bash
    # pacman -S bash
    # pacman -Su
    Should I replace bash with zsh here? I do have both bash and zsh installed.
    EDIT: I did indeed forget to mount /boot. After doing that the update worked perfectly.
    Last edited by graph (2013-06-03 19:23:37)

    Alright, I have one working shell. I have no Ignores but I do have
    HoldPkg = pacman glibc
    in /etc/pacman.conf - Could this be the culprit?
    Also, here are the (missing) output of the commands from the article. I'm quite interested in knowing whether all my autofs-partitions are mounted, which I believe they are.
    # pacman -Qqo /bin /sbin /usr/sbin | pacman -Qm -
    # find /bin /sbin /usr/sbin -exec pacman -Qo -- {} + >/dev/null
    # mount
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    sys on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
    dev on /dev type devtmpfs (rw,nosuid,relatime,size=1538736k,nr_inodes=216743,mode=755)
    run on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
    /dev/sda5 on / type ext4 (rw,relatime,data=ordered)
    securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
    tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,mode=755)
    cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
    pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
    cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
    cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
    cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
    cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
    cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
    cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
    cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
    systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=33,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
    systemd-1 on /boot type autofs (rw,relatime,fd=36,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
    systemd-1 on /home type autofs (rw,relatime,fd=37,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
    configfs on /sys/kernel/config type configfs (rw,relatime)
    debugfs on /sys/kernel/debug type debugfs (rw,relatime)
    mqueue on /dev/mqueue type mqueue (rw,relatime)
    tmpfs on /tmp type tmpfs (rw)
    hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
    /dev/sda6 on /home type ext4 (rw,noatime,data=ordered)
    binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime)
    Last edited by graph (2013-06-03 18:00:47)

  • 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.

  • [Solved] zsh and pkexec

    [Synopsys] Edit /etc/shells manually, and add /bin/zsh to the list of shells and specify the full path to the app in the policy file. i.e. /usr/bin/leafpad and NOT just leafpad. The policy file for gparted serves as a good one to model your own policy files after.
    My environment variable SHELL is still being set to /bin/zsh even though binaries have been moved to /usr/bin/zsh making pkexec complain and fail to run apps in privileged mode.
    Where is SHELL set and where would be the most appropriate place to fix it globally for all users?
    Last edited by KairiTech (2013-06-29 20:53:49)

    karol wrote:What exactly does pkexec say?
    The value for the SHELL variable was not found the /etc/shells file
    This incident has been reported.
    ...but if I set SHELL like so...
    export SHELL=`which zsh` ; pkexec gnome-system-monitor !
    ...after I enter a password the error message changes to...
    (process:9562): GLib-WARNING **: GChildWatchSource: Exit status of a child process was requested but ECHILD was received by waitpid(). Most likely the process is ignoring SIGCHLD, or some other thread is invoking waitpid() with a nonpositive first argument; either behavior can break applications that use g_child_watch_add()/g_spawn_sync() either directly or indirectly.
    ==== AUTHENTICATION COMPLETE ===
    (gnome-system-monitor:9562): Gtk-WARNING **: cannot open display:
    Last edited by KairiTech (2013-06-29 17:40:34)

  • Help with php and regular expressions

    I am making a package and would like php to execute sed - command during setup (when user goes to installation php page and submits info). Like this:
    exec("sed -i 's|^.*$db_host.*$|$db_host="$HOST";|' config.php");
    exec("sed -i 's|^.*$db_user.*$|$db_user="$IPUSER";|' config.php");
    exec("sed -i 's|^.*$db_password.*$|$db_password="$IPUSERPASS";|' config.php");
    exec("sed -i 's|^.*$db_name.*$|$db_name="$DBNAME";|' config.php");
    exec("sed -i 's|^.*$url_base.*$|$url_base="$URLBASE";|' config.php");
    Apparently something is wrong with escapes because sed never gets any matches that it would replace.

    phrakture wrote:
    mmgm wrote:
    cactus wrote:and there is no reason to stick a .* on the front of the regexp. Just make sure the variables have no blank space at the start of the line in front of them.
    Making sure you have no blank space before the variable is quite a demand for people obsessed with tabbing, like me.
    I swear, if my tab key ever breaks, I'm gonna start smashing things.
    I'm such a clean-code-whore.
    but this is a config file... do you really tab out your config files?
    Config files are usually ment to be human-readable. This is why they usually contain comments and such. Tabbing makes code more readable and therefore I find it usefull in any file which contains text of any sort. In the end, it's going to make your life a whole lot easier.

Maybe you are looking for

  • Managing Word Templates in Organization on a network location

    Hi We use Word 2013 and started to use corporate templates currently, our templates are located on our SharePoint Online, which means they're on the web, though most of the users have the template directory synced offline to their local drive with On

  • Regarding events in alv reports

    Dear Friends,         Sorry for this post, Events not triggering in alv reports. There is no errors and no warnings.I am using interactive reports. Please tell me where could be i went wrong. It is displaying basic list information but with out event

  • CUP 5.3 (SP11) Risk Owner Approval in CUP workflow

    Hello Experts, I have a question... When you create a risk in RAR, is there any way you can send an approval request automatically to a Risk Owner already set in RAR? Unfortunately, there is no such option for risk in the CUP custom approver determin

  • Quick noob boot question

    on boot a couple of lines near the end read: xxx write tlv xxx write tlv just wondered if they mean anything significant. I don't think they were there when I first installed Arch. no problems otherwise, I'm loving Arch thanks

  • DVDSP4 stalls on startup splash window

    Has anyone else run into this issue? I start the application and the splash page comes up and then it just sits there. I've walked away, thinking maybe it's just taking a while to start up (as it sometimes will) and come back 30 minutes later and it'