TechnicalRegEx help pls

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  milko  
 To:  ALL
41616.1 
I'm a bit thick with things like this.

I want to search a spreadsheet column and highlight all cells that do not contain one of three* strings.

LibreOffice supports Regex in its Find function so that's pretty useful, this ought to be doable, right?

A bit of googling has got me the following:

^(.(?!mov).(?!mpg).(?!mp4))*$

Which seems to sort of work but not quite? In that it is returning some false positives, and I don't know why.

*it is possible that later on I might want to change this search to more or less strings so if your help also allows for that then it is double good.

Thanks!
milko
0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  milko     
41616.2 In reply to 41616.1 
I use online regex testers (like this, there's a whole bunch of 'em) to work out stuff like that.

----
Dog named Trigger accidentally shoots owner.
0/0
 Reply   Quote More 

 From:  koswix  
 To:  CHYRON (DSMITHHFX)     
41616.3 In reply to 41616.2 
PB 's native language is regex. Little known fact, he did once disclose his favourite pizza topping, but the regex used to select it is so complicated no human or non-AI digital computer has yet been able to decipher it.

 ▪                    
             ┌────┐    ┌────┐                      
          │    │    │    │ ▪                    
          │    └────┘    │                      
          │   ──┐  ┌──   │ ▪                    
   ┌──────┤    ▪    ▪    │                      
  ┌┘      │              │ ▪                    
┌─┤       └──┐  │  │  ┌──┘                      
│ │          │ ││  ││ │   ┌─┐                   
│ │          └─┼┤  └┴─┴───┘ │                   
│ │           ─┘│           │                   
│ │   ┌──────┐  └┬──────────┘                   
  │   │      │   │                              
  │   │      │   │                              
  └───┘      └───┘                              
If Feds call you and say something bad on me, it may prove what I said are truth, they are afraid of it.

+1/1
 Reply   Quote More 

 From:  milko  
 To:  CHYRON (DSMITHHFX)     
41616.4 In reply to 41616.2 
That seems like before it'll help me I will need to get more of the basics in my head. In that it is telling me stuff about my expression, but I'm finding little of that any use. Bookmarked!

 
milko
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  milko     
41616.5 In reply to 41616.1 
The closest thing to what you appear to be trying is this:
	^(?:(?!mov|mpg|mp4).)*$

The negative lookahead (?!this) needs to be before the . and the alternation (this|stuff) handles the different strings being checked.

The outer (?:group) is almost the same as just (this) but slightly more efficient (probably not noticeably so, but it's only two extra characters).

If what you actually have is one filename per cell and you want to exclude those file extensions, a better way (that won't exclude "asmov.jpg" for example), would be:

	^.*$(?<!\.(?:mov|mpg|mp4))

This matches the entire string with ^.*$ then uses the negative lookbehind (?<!this) to exclude the extensions from occurring there (with a preceeding . character, which the slash escapes).

Both versions allow extra strings added just by appending |more|items|yay appropriately.

0/0
 Reply   Quote More 

 From:  milko  
 To:  Peter (BOUGHTONP)     
41616.6 In reply to 41616.5 
Now that's what I'm talking about. Thanks, Peter! Does the job perfectly. Now to think of what other situations this kind of thing will help me in.
milko
0/0
 Reply   Quote More 

 From:  koswix  
 To:  CHYRON (DSMITHHFX)     
41616.7 In reply to 41616.5 
See?

 ▪                    
             ┌────┐    ┌────┐                      
          │    │    │    │ ▪                    
          │    └────┘    │                      
          │   ──┐  ┌──   │ ▪                    
   ┌──────┤    ▪    ▪    │                      
  ┌┘      │              │ ▪                    
┌─┤       └──┐  │  │  ┌──┘                      
│ │          │ ││  ││ │   ┌─┐                   
│ │          └─┼┤  └┴─┴───┘ │                   
│ │           ─┘│           │                   
│ │   ┌──────┐  └┬──────────┘                   
  │   │      │   │                              
  │   │      │   │                              
  └───┘      └───┘                              
If Feds call you and say something bad on me, it may prove what I said are truth, they are afraid of it.

+1/1
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  koswix     
41616.8 In reply to 41616.7 
:-/

----
Dog named Trigger accidentally shoots owner.
0/0
 Reply   Quote More 

 From:  koswix  
 To:  CHYRON (DSMITHHFX)     
41616.9 In reply to 41616.8 
I know, right?

 ▪                    
             ┌────┐    ┌────┐                      
          │    │    │    │ ▪                    
          │    └────┘    │                      
          │   ──┐  ┌──   │ ▪                    
   ┌──────┤    ▪    ▪    │                      
  ┌┘      │              │ ▪                    
┌─┤       └──┐  │  │  ┌──┘                      
│ │          │ ││  ││ │   ┌─┐                   
│ │          └─┼┤  └┴─┴───┘ │                   
│ │           ─┘│           │                   
│ │   ┌──────┐  └┬──────────┘                   
  │   │      │   │                              
  │   │      │   │                              
  └───┘      └───┘                              
If Feds call you and say something bad on me, it may prove what I said are truth, they are afraid of it.

0/0
 Reply   Quote More 

 From:  Kenny J (WINGNUTKJ)  
 To:  Peter (BOUGHTONP)     
41616.10 In reply to 41616.5 
Bravo!

After avoiding the things for years, the software I work with has suddenly sprouted a regex based text file parsing engine, and I'm having to try to remember everything I ever knew about them.

Kenny
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Kenny J (WINGNUTKJ)     
41616.11 In reply to 41616.10 
When ever I see regex i just pretend I'm hacking a terminal in Fallout 3.

 ▪                    
             ┌────┐    ┌────┐                      
          │    │    │    │ ▪                    
          │    └────┘    │                      
          │   ──┐  ┌──   │ ▪                    
   ┌──────┤    ▪    ▪    │                      
  ┌┘      │              │ ▪                    
┌─┤       └──┐  │  │  ┌──┘                      
│ │          │ ││  ││ │   ┌─┐                   
│ │          └─┼┤  └┴─┴───┘ │                   
│ │           ─┘│           │                   
│ │   ┌──────┐  └┬──────────┘                   
  │   │      │   │                              
  │   │      │   │                              
  └───┘      └───┘                              
If Feds call you and say something bad on me, it may prove what I said are truth, they are afraid of it.

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Kenny J (WINGNUTKJ)     
41616.12 In reply to 41616.10 
Sometimes I wonder why people avoid regex, given that it's easier than most other languages, particularly any general purpose one.

Then I remember there's a reason software has so many bugs in. :/

0/0
 Reply   Quote More 

 From:  Kenny J (WINGNUTKJ)  
 To:  Peter (BOUGHTONP)     
41616.13 In reply to 41616.12 
There's a reason that software has so many bugs in, but I don't think it's anything to do with regular expressions. Top 3 in my office: Lack of testing, lack of review oversight, lack of understanding of requirements.

I think you answered your question about why people avoid regex up there, by posting a bit of Regex. It's an arcane and very compact syntax with very little in common to natural language, and is therefore a pain in the arse to maintain if you're not dealing with it day in, day out.

I took to adding exhaustive comments to any regex I wrote, because I knew that in six months time, some idiot would be picking through the code trying to figure out what it was doing. I wanted to give them as much information as possible about what the expression was for, and how it worked, because there would be a fairly good chance that idiot would be me.

Kenny
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Kenny J (WINGNUTKJ)     
41616.14 In reply to 41616.13 
What? No, I wasn't saying it had anything to do with regex itself.

If developers don't understand the relatively simple concepts involved in regex, it's no surprise they don't understand and correctly apply the more advanced concepts found in complex programming.

Lack of understanding of requirements is definitely another problem, as is lack of testing (both automated and human).

Or put another way: most developers don't know what the problem is, don't really know how to solve it, and don't want to verify their thrown together mess actually does what was asked for, beyond very superficial and cursory one-off checks.

Not certain what lack of review oversight means?


> It's an arcane and very compact syntax with very little in common to natural language

That's the thing - it's not really any worse than many other computer languages, when you take the whitespace away.

These are just as gibberish to a newbie or non-programmer as a regex is:

   var url=$('a[href^=#]:eq(0)').val();
   <?=((int)$_POST['c'])?:__('none')?>

You might not write code like that, but equally regex can be written with whitespace and comments too (and it's a shame that's not the default).

   # match entire string
   ^.*$

   # don't match video files
   (?<!
      \.(?:mov|mpg|mp4)
   )

A contrived example, and that first comment is akin to an "increment by one" line, but it hopefully demonstrates the problem is less the language.

The second comment is more the sort that should be written - explaining the intent of the code, so if there's a bug then the idiot in six months time has a chance of knowing whether something unusual is deliberate or the cause. (Of course, any deliberately unusual behaviour should also have suitable positive and negative test cases to prevent regression.)

0/0
 Reply   Quote More 

Reply to All    
 

1–14

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats