Sponsored Content
Top Forums Shell Programming and Scripting regular expression to match repeated appearance Post 302365213 by guruparan18 on Monday 26th of October 2009 10:26:54 AM
Old 10-26-2009
regular expression to match repeated appearance

Hi all,

I am looking for a regex syntax to match repeated appearance. Likes,

Code:
'[[:alnum]]+[[:alnum:]]+' matches for string '65A SOME MORE AND 78B'

Now, this gets messy if I need to extract all such repeated appearance. I don't want to write [[:alnum:]] four or five times for matching repeated appearance.

Thanks in advance.

---------- Post updated at 07:56 PM ---------- Previous update was at 07:43 PM ----------

Basically, I am looking at extracting all alpha numeric from the string. Doesn't matter how many times it appears in the string.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Exact match with regular expression

Hi I have a file with data arranged into columns. The first column is the chromosome name. When I use grep to subset only rows with chr1, I get chr1 but also chr10, chr11,.. How do I get only rows with chr1? grep chr1 filein > fileout head fileout chr1 59757841 chr11 108258691 ... (2 Replies)
Discussion started by: jdhahbi
2 Replies

2. UNIX for Dummies Questions & Answers

Regular Expression - match 'b' that follows 'a' and is at the end of a string

Hi, I'm struggling with a regex that would match a 'b' that follows an 'a' and is at the end of a string of non-white characters. For example: Line 1: aba abab b abb aab bab baa I can find the right strings but I'm lacking knowledge of how to "discard" the bits that precede bs.... (2 Replies)
Discussion started by: machinogodzilla
2 Replies

3. Shell Programming and Scripting

Regular expression match

Hi all, any idea how to match the following: char*<no or any string or space> buf and char *<no or any string or space> buf i need to capture the buf characters too. currently i need two checks to cover this: #search char* <any string> buf or char *<any string> buf @noarray =... (2 Replies)
Discussion started by: ChaMeN
2 Replies

4. Shell Programming and Scripting

Regular Expression to match repeated characters

Hello All I have file which contain sample data like below - test.txt ---------------------------------------------- jambesh aaa india trxxx sdasd mentor asss light train bbblah --------------------------------------------- I want to write a regX which would print only those... (4 Replies)
Discussion started by: jambesh
4 Replies

5. Shell Programming and Scripting

regular expression match

I am trying to match a similar line using grep with regular expression the line is /remote/mac/pbbbb/abc/def/hij/hop/include/abc/tif/element/test/testfiles/Office.cpp:57: const OfficeType& getType().get() const; I just need to extract the bold characters using grep with regular expression.... (5 Replies)
Discussion started by: prasbala
5 Replies

6. Shell Programming and Scripting

regular expression exact match

hi everyone suppose we have two scenario echo ABCD | grep \{4\} DATE echo SYSDATE | grep \{4\} SYSDATE i want to match the string of four length only please help (5 Replies)
Discussion started by: aishsimplesweet
5 Replies

7. Homework & Coursework Questions

Regular Expression to match files in Perl

Hi Everybody! I need some help with a regular expression in Perl that will match files named messages, but also files named message.1, message.2 and so on. So really I need one that will find messages and messages that might be followed by a period and a digit without matching other files like... (2 Replies)
Discussion started by: Hax0rc1ph3r
2 Replies

8. Shell Programming and Scripting

Perl split match regular expression with or

I cannot seem to get this to work correct: my ($k, $v) = split(/F/, $fc{$DIR}{symbolic}, 2); Below is the input (the $fc{$DIR}{symbolic} variable): QMH2562 FW:v5.06.03 DVR:v8.03.07.15.05.09-kbut i also need it to break on FV: Emulex NC553i FV4.2.401.6 DV8.3.5.86.2pthe code above... (2 Replies)
Discussion started by: rusted_planet
2 Replies

9. Shell Programming and Scripting

Regular expression to match multiple lines?

Using a regular expression, I would like multiple lines to be matched. By default, a period (.) matches any character except newline. However, (?s) and /s modifiers are supposed to force . to accept a newline and to match any character including a newline. However, the following two perl... (4 Replies)
Discussion started by: LessNux
4 Replies

10. Shell Programming and Scripting

Regular expression match

echo 20110101 | awk '{ print match($0,/^((17||18||19||20)|)-*(|0|1)-*(|0||3)$/)) I am getting a match for the above, where as it shouldn't, as there is no hyphen in the echoed date. Another question is what is the difference between || and | in the above statement (4 Replies)
Discussion started by: tostay2003
4 Replies
regcmp(3C)						   Standard C Library Functions 						regcmp(3C)

NAME
regcmp, regex - compile and execute regular expression SYNOPSIS
#include <libgen.h> char *regcmp(const char *string1, /* char *string2 */ ..., int /*(char*)0*/); char *regex(const char *re, const char *subject, /* char *ret0 */ ...); extern char *__loc1; DESCRIPTION
The regcmp() function compiles a regular expression (consisting of the concatenated arguments) and returns a pointer to the compiled form. The malloc(3C) function is used to create space for the compiled form. It is the user's responsibility to free unneeded space so allocated. A NULL return from regcmp() indicates an incorrect argument. regcmp(1) has been written to generally preclude the need for this routine at execution time. The regex() function executes a compiled pattern against the subject string. Additional arguments are passed to receive values back. The regex() function returns NULL on failure or a pointer to the next unmatched character on success. A global character pointer __loc1 points to where the match began. The regcmp() and regex() functions were mostly borrowed from the editor ed(1); however, the syntax and semantics have been changed slightly. The following are the valid symbols and associated meanings. []*.^ This group of symbols retains its meaning as described on the regexp(5) manual page. $ Matches the end of the string; matches a newline. - Within brackets the minus means through. For example, [a-z] is equivalent to [abcd...xyz]. The - can appear as itself only if used as the first or last character. For example, the character class expression []-] matches the characters ] and -. + A regular expression followed by + means one or more times. For example, [0-9]+ is equivalent to [0-9][0-9]*. {m} {m,} {m,u} Integer values enclosed in {} indicate the number of times the preceding regular expression is to be applied. The value m is the minimum number and u is a number, less than 256, which is the maximum. If only m is present (that is, {m}), it indicates the exact number of times the regular expression is to be applied. The value {m,} is analogous to {m,infinity}. The plus (+) and star (*) operations are equivalent to {1,} and {0,} respectively. ( ... )$n The value of the enclosed regular expression is to be returned. The value will be stored in the (n+1)th argument follow- ing the subject argument. At most, ten enclosed regular expressions are allowed. The regex() function makes its assign- ments unconditionally. ( ... ) Parentheses are used for grouping. An operator, for example, *, +, {}, can work on a single character or a regular expression enclosed in parentheses. For example, (a*(cb+)*)$0. By necessity, all the above defined symbols are special. They must, therefore, be escaped with a (backslash) to be used as themselves. EXAMPLES
Example 1 Example matching a leading newline in the subject string. The following example matches a leading newline in the subject string pointed at by cursor. char *cursor, *newcursor, *ptr; ... newcursor = regex((ptr = regcmp("^ ", (char *)0)), cursor); free(ptr); The following example matches through the string Testing3 and returns the address of the character after the last matched character (the ``4''). The string Testing3 is copied to the character array ret0. char ret0[9]; char *newcursor, *name; ... name = regcmp("([A-Za-z][A-za-z0-9]{0,7})$0", (char *)0); newcursor = regex(name, "012Testing345", ret0); The following example applies a precompiled regular expression in file.i (see regcmp(1)) against string. #include "file.i" char *string, *newcursor; ... newcursor = regex(name, string); ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
ed(1), regcmp(1), malloc(3C), attributes(5), regexp(5) NOTES
The user program may run out of memory if regcmp() is called iteratively without freeing the vectors no longer required. When compiling multithreaded applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in mul- tithreaded applications. SunOS 5.11 14 Nov 2002 regcmp(3C)
All times are GMT -4. The time now is 02:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy