Sponsored Content
Full Discussion: Regex?? Please help
Top Forums UNIX for Dummies Questions & Answers Regex?? Please help Post 302105064 by anbu23 on Tuesday 30th of January 2007 12:10:07 PM
Old 01-30-2007
Code:
echo "76 +myproject 013107 mics text" | sed 's/^.*\(\+[^ ]*\).*/\1/g'

\(\+[^ ]*\) this match string contains + and followed by any characters other than space.
.* matches any number of characters
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regex

Hi, i want to match a string using perl that has got 5 pluses(+++++). i am using a function for this. $str1="+++++"; check($str1,"\\+"); sub check{ $str1=$_; $str2=$_; if($str1=~m/^$str2{5}$/){ print "Correct.\n"; }else{ print "Wrong..\n"; ... (6 Replies)
Discussion started by: deepakpv
6 Replies

2. Shell Programming and Scripting

Need a regex

Hi, I am trying to grep for the following type of string from a document given below: 12637 1239 3356 12956 7004 7004 7004 13381 13381 *> 12.0.1.63 0 7018 21872 ? * 208.51.134.254 53 0 3549 7018 21872 ?... (1 Reply)
Discussion started by: Legend986
1 Replies

3. UNIX for Dummies Questions & Answers

regex

Can anyone give the detailed explanation on regex search i want to know the use of regex in sed and awk also...... the operators like ^,.,* ....etc i need it with some example.....kindly help on this. I gone through the man pages also..but i was not clear......... (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

4. Shell Programming and Scripting

regex help

I would like to search strings composed by only one type of charachter for example only strings composed by the charachter 'b' is it right? $egrep '\<(b+)+\>' filename Could be there some side effects? Regards. (1 Reply)
Discussion started by: and77
1 Replies

5. Shell Programming and Scripting

Converting perl regex to sed regex

I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly: if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies

6. Shell Programming and Scripting

Regex for First and Last name

I have a regex I'd like to implement and I believe it should be working and I have tested it on various websites that have regex testers but it always says the name is invalid. #!/bin/bash -x echo Enter the users first and last name. read name if... (11 Replies)
Discussion started by: woodson2
11 Replies

7. UNIX for Dummies Questions & Answers

read regex from ID file, print regex and line below from source file

I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header. In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

8. Shell Programming and Scripting

Perl, RegEx - Help me to understand the regex!

I am not a big expert in regex and have just little understanding of that language. Could you help me to understand the regular Perl expression: ^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{ ------ This is regex to select functions from a C/C++ source and defined in... (2 Replies)
Discussion started by: alex_5161
2 Replies

9. UNIX for Beginners Questions & Answers

Using Regex

Here i am writing a script to check&display only the valid mail address from a file echo "Plz enter the Target file name with path" read path if then echo "The valid mail address are:" email=$(grep -E -o "\b+@+\.{2,6}\b" $path ) echo "$email" fi The file contains the data like this:... (6 Replies)
Discussion started by: Meeran Rizvi
6 Replies

10. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies
DateTime::Format::Builder::Parser(3pm)			User Contributed Perl Documentation		    DateTime::Format::Builder::Parser(3pm)

NAME
DateTime::Format::Builder::Parser - Parser creation SYNOPSIS
my $class = 'DateTime::Format::Builder::Parser'; my $parser = $class->create_single_parser( %specs ); DESCRIPTION
This is a utility class for DateTime::Format::Builder that handles creation of parsers. It is to here that "Builder" delegates most of its responsibilities. CONSTRUCTORS
METHODS
There are two sorts of methods in this class. Those used by parser implementations and those used by "Builder". It is generally unlikely the user will want to use any of them. They are presented, grouped according to use. Parameter Handling (implementations) These methods allow implementations to have validation of their arguments in a standard manner and due to "Parser"'s impelementation, these methods also allow "Parser" to determine which implementation to use. Common parameters These parameters appear for all parser implementations. These are primarily documented in the main docs. o on_match o on_fail o postprocess o preprocess o label o length may be a number or an arrayref of numbers indicating the length of the input. This lets us optimise in the case of static length input. If supplying an arrayref of numbers, please keep the number of numbers to a minimum. params my $params = $self->params(); validate( @_, $params ); Returns declared parameters and "common" parameters in a hashref suitable for handing to Params::Validate's "validate" function. params_all my $all_params = $self->params_all(); Returns a hash of all the valid options. Not recommended for general use. valid_params __PACKAGE__->valid_params( %params ); Arguments are as per Params::Validate's "validate" function. This method is used to declare what your valid arguments are in a parser specification. whose_params my $class = whose_params( $key ); Internal function which merely returns to which class a parameter is unique. If not unique, returns "undef". Organising and Creating Parsers create_single_parser This takes a single specification and returns a coderef that is a parser that suits that specification. This is the end of the line for all the parser creation methods. It delegates no further. If a coderef is specified, then that coderef is immediately returned (it is assumed to be appropriate). The single specification (if not a coderef) can be either a hashref or a hash. The keys and values must be as per the specification. It is here that any arrays of callbacks are unified. It is also here that any parser implementations are used. With the spec that's given, the keys are looked at and whichever module is the first to have a unique key in the spec is the one to whom the spec is given. Note: please declare a "valid_params" argument with an uppercase letter. For example, if you're writing "DateTime::Format::Builder::Parser::Fnord", declare a parameter called "Fnord". Similarly, "DTFBP::Strptime" should have "Strptime" and "DTFBP::Regex" should have "Regex". These latter two don't for backwards compatibility reasons. The returned parser will return either a "DateTime" object or "undef". merge_callbacks Produce either undef or a single coderef from either undef, an empty array, a single coderef or an array of coderefs create_multiple_parsers Given the options block (as made from "create_parser()") and a list of single parser specifications, this returns a coderef that returns either the resultant "DateTime" object or "undef". It first sorts the specifications using "sort_parsers()" and then creates the function based on what that returned. sort_parsers This takes the list of specifications and sorts them while turning the specifications into parsers. It returns two values: the first is a hashref containing all the length based parsers. The second is an array containing all the other parsers. If any of the specs are not code or hash references, then it will call "croak()". Code references are put directly into the 'other' array. Any hash references without length keys are run through "create_single_parser()" and the resultant parser is placed in the 'other' array. Hash references with length keys are run through "create_single_parser()", but the resultant parser is used as the value in the length hashref with the length being the key. If two or more parsers have the same length specified then an error is thrown. create_parser "create_class()" is mostly a wrapper around "create_parser()" that does loops and stuff and calls "create_parser()" to create the actual parsers. "create_parser()" takes the parser specifications (be they single specifications or multiple specifications) and returns an anonymous coderef that is suitable for use as a method. The coderef will call "croak()" in the event of being unable to parse the single string it expects as input. The simplest input is that of a single specification, presented just as a plain hash, not a hashref. This is passed directly to "create_single_parser()" with the return value from that being wrapped in a function that lets it "croak()" on failure, with that wrapper being returned. If the first argument to "create_parser()" is an arrayref, then that is taken to be an options block (as per the multiple parser specification documented earlier). Any further arguments should be either hashrefs or coderefs. If the first argument after the optional arrayref is not a hashref or coderef then that argument and all remaining arguments are passed off to "create_single_parser()" directly. If the first argument is a hashref or coderef, then it and the remaining arguments are passed to "create_multiple_parsers()". The resultant coderef from calling either of the creation methods is then wrapped in a function that calls "croak()" in event of failure or the "DateTime" object in event of success. FINDING IMPLEMENTATIONS
"Parser" automatically loads any parser classes in @INC. To be loaded automatically, you must be a "DateTime::Format::Builder::Parser::XXX" module. To be invisible, and not loaded, start your class with a lower class letter. These are ignored. WRITING A PARSER IMPLEMENTATION
Naming your parser Create a module and name it in the form "DateTime::Format::Builder::Parser::XXX" where XXX is whatever you like, so long as it doesn't start with a lower case letter. Alternatively, call it something completely different if you don't mind the users explicitly loading your module. I'd recommend keeping within the "DateTime::Format::Builder" namespace though --- at the time of writing I've not given thought to what non-auto loaded ones should be called. Any ideas, please email me. Declaring specification arguments Call "<DateTime::Format::Builder::Parser-"valid_params()>> with "Params::Validate" style arguments. For example: DateTime::Format::Builder::Parser->valid_params( params => { type => ARRAYREF }, Regex => { type => SCALARREF, callbacks => { 'is a regex' => sub { ref(shift) eq 'Regexp' } }} ); Start one of the key names with a capital letter. Ideally that key should match the XXX from earlier. This will be used to help identify which module a parser specification should be given to. The key names on_match, on_fail, postprocess, preprocess, label and length are predefined. You are recommended to make use of them. You may ignore length as "sort_parsers" takes care of that. Define create_parser A class method of the name "create_parser" that does the following: Its arguments are as for a normal method (i.e. class as first argument). The other arguments are the result from a call to "Params::Validate" according to your specification (the "valid_params" earlier), i.e. a hash of argument name and value. The return value should be a coderef that takes a date string as its first argument and returns either a "DateTime" object or "undef". Callbacks It is preferred that you support some callbacks to your parsers. In particular, "preprocess", "on_match", "on_fail" and "postprocess". See the main Builder docs for the appropriate placing of calls to the callbacks. SUPPORT
Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. Alternatively, log them via the CPAN RT system via the web or email: http://perl.dellah.org/rt/dtbuilder bug-datetime-format-builder@rt.cpan.org This makes it much easier for me to track things and thus means your problem is less likely to be neglected. THANKS
See DateTime::Format::Builder. LICENCE AND COPYRIGHT
Copyright X Iain Truskett, 2003. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.000 or, at your option, any later version of Perl 5 you may have available. The full text of the licences can be found in the Artistic and COPYING files included with this module, or in perlartistic and perlgpl as supplied with Perl 5.8.1 and later. AUTHOR
Iain Truskett <spoon@cpan.org> SEE ALSO
"datetime@perl.org" mailing list. http://datetime.perl.org/ perl, DateTime, DateTime::Format::Builder. Params::Validate. DateTime::Format::Builder::Parser::generic, DateTime::Format::Builder::Parser::Dispatch, DateTime::Format::Builder::Parser::Quick, DateTime::Format::Builder::Parser::Regex, DateTime::Format::Builder::Parser::Strptime. perl v5.10.1 2010-03-14 DateTime::Format::Builder::Parser(3pm)
All times are GMT -4. The time now is 04:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy