Sponsored Content
Full Discussion: Simple regex problem?
Top Forums Shell Programming and Scripting Simple regex problem? Post 302302532 by muay_tb on Tuesday 31st of March 2009 08:13:38 AM
Old 03-31-2009
Simple regex problem?

Hi all,

I am looking to create words from a sentence which adhere to a custom search pattern from my website:

Example:

![hello] +![bye] /[said] +=[from] ~[to]

where the terms ! = not, +! = AND NOT, += - and equals and ~ = can be like....

Now here is the issue...i want to split a sentence like the one above on spaces, this is easily done in PHP with a simple split on " ". However this will not work if i have something like:

![hello] +![bye] /[said] +=[from] ~[to] my name

as my name is not surrounded with any of the custom tags and has a space in it...

so basically my output should be:

![hello]
+![bye]
/[said]
+=[from]
~[to]
my name

Any help people? SmilieSmilie

Last edited by muay_tb; 03-31-2009 at 12:07 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep regex problem

Hi, I am trying to do something with grep, but for some reason I just can't get it to to work. I am looking for find a match in the second field, the length must be 10 characters and end with 'abc'. The file is in this format: <int><tab><field2> I've tried a few patterns, some work,... (2 Replies)
Discussion started by: iceman
2 Replies

2. Shell Programming and Scripting

A simple find and replace without using any regex (bash)

Hi, I need to do an exact find and replace (I don't want to use regular expressions because the input comes from user). I want to find a line that matches the user's input text and replace it with an empty string. For example, let's say the user enters I love "Unix" and the contents of the... (2 Replies)
Discussion started by: srikanths
2 Replies

3. Shell Programming and Scripting

Need Help with Simple Regex

I have got a question. How to do this? I mean AND expression in regex. List all the files in current directory that do not contain the words use AND take. Thx.:p (15 Replies)
Discussion started by: evilfreakz
15 Replies

4. Shell Programming and Scripting

regex problem

Hi, #!/usr/bin/perl -w my $timestamp; my $line = "Fri May 29 18:29:57.357 2009 Morocco Standard Time INFO: pid 3216 tid 1724: 170: 132192: apricocot Native Server: recvd AA_BIN_MSG_VER_CHG"; if ($line =~ /^(.*) INFO: .* recvd AA_BIN_MSG_VER_CHG/) { $timestamp = $1; ... (1 Reply)
Discussion started by: namishtiwari
1 Replies

5. UNIX for Dummies Questions & Answers

regex problem with +

Hi, Can someone tell me why the first regular expression with the + fails to match the input string? SUN /web>echo cat | grep '+' SUN /web>echo cat | grep '' cat I'm running SunOS 5.10 Thanks. Chris (2 Replies)
Discussion started by: che9000
2 Replies

6. Programming

REGEX problem

Hi there, How can we use regex in perl to store the Route Distinguisher (the bold field) and also the underlined and bold lines in the below file? Note: These highlighted pattern is redundant through the whole input file. Basically, we just need to extract these fields at least to store them... (4 Replies)
Discussion started by: omoyne
4 Replies

7. Shell Programming and Scripting

Help with simple RegEx on grep

Hello, I am trying to grep my log files for ORA errors, except ORA-00001. I have tried: grep 'ORA*!(-00001)' *.log but it is not working. Any help will be much appreciated. Thank you. (5 Replies)
Discussion started by: drbiloukos
5 Replies

8. Shell Programming and Scripting

help with simple regex expression

I am trying to grep the following line in a file using a bash shell: (..) admin1::14959:::::: (..) It works with the following expression (as expected) # cat file | grep ^*:: admin1::14959:::::: but it does not work with (not expected) # cat /etc/shadow | grep ^+:: I assume the... (2 Replies)
Discussion started by: schms
2 Replies

9. Programming

Regex problem

Hi, I am looking for regex to extract following words from text: The word which comes after "Replaced" means Replaced disk Replaced floppy Replaced memory Please suggest the regex for it. Thanks! (4 Replies)
Discussion started by: gunjanamit
4 Replies

10. UNIX for Dummies Questions & Answers

All combinations from simple regex

Hi ! Before trying to write a code, is there any program or code that generates all the combinations of strings that simple awk regex can match. By "simple regex" I mean let's say without "+", "*", and with a limited number of characters (e.g. from "1" to "5"). e.g: input: 34?5 output:... (9 Replies)
Discussion started by: beca123456
9 Replies
FMT(1)							    BSD General Commands Manual 						    FMT(1)

NAME
fmt -- simple text formatter SYNOPSIS
fmt [-cmnps] [-d chars] [-l num] [-t num] [goal [maximum] | -width | -w width] [file ...] DESCRIPTION
The fmt utility is a simple text formatter which reads the concatenation of input files (or standard input if none are given) and produces on standard output a version of its input with lines as close to the goal length as possible without exceeding the maximum. The goal length defaults to 65 and the maximum to 10 more than the goal length. Alternatively, a single width parameter can be specified either by prepend- ing a hyphen to it or by using -w. For example, ``fmt -w 72'', ``fmt -72'', and ``fmt 72 72'' all produce identical output. The spacing at the beginning of the input lines is preserved in the output, as are blank lines and interword spacing. Lines are joined or split only at white space; that is, words are never joined or hyphenated. The options are as follows: -c Center the text, line by line. In this case, most of the other options are ignored; no splitting or joining of lines is done. -m Try to format mail header lines contained in the input sensibly. -n Format lines beginning with a '.' (dot) character. Normally, fmt does not fill these lines, for compatibility with nroff(1). -p Allow indented paragraphs. Without the -p flag, any change in the amount of whitespace at the start of a line results in a new para- graph being begun. -s Collapse whitespace inside lines, so that multiple whitespace characters are turned into a single space. (Or, at the end of a sen- tence, a double space.) -d chars Treat the chars (and no others) as sentence-ending characters. By default the sentence-ending characters are full stop ('.'), ques- tion mark ('?') and exclamation mark ('!'). Remember that some characters may need to be escaped to protect them from your shell. -l number Replace multiple spaces with tabs at the start of each output line, if possible. Each number spaces will be replaced with one tab. The default is 8. If number is 0, spaces are preserved. -t number Assume that the input files' tabs assume number spaces per tab stop. The default is 8. The fmt utility is meant to format mail messages prior to sending, but may also be useful for other simple tasks. For instance, within vis- ual mode of the ex(1) editor (e.g., vi(1)) the command !}fmt will reformat a paragraph, evening the lines. ENVIRONMENT
The LANG, LC_ALL and LC_CTYPE environment variables affect the execution of fmt as described in environ(7). SEE ALSO
fold(1), mail(1), nroff(1) HISTORY
The fmt command appeared in 3BSD. The version described herein is a complete rewrite and appeared in FreeBSD 4.4. AUTHORS
Kurt Shoens Liz Allen (added goal length concept) Gareth McCaughan BUGS
The program was designed to be simple and fast - for more complex operations, the standard text processors are likely to be more appropriate. When the first line of an indented paragraph is very long (more than about twice the goal length), the indentation in the output can be wrong. The fmt utility is not infallible in guessing what lines are mail headers and what lines are not. BSD
August 2, 2004 BSD
All times are GMT -4. The time now is 06:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy