regex halp
1
Name:
Anonymous
2010-09-16 16:37
can anyone help with the following regex?
[0 or more whitespace characters] + #define + [1 or more whitespace characters] + NULL + [1 or more whitespace characters]
thank u
2
Name:
Anonymous
2010-09-16 16:40
Read SICP
3
Name:
Anonymous
2010-09-16 16:42
Just pipe a grep into another. Regexen appear to be too difficult. Observe:
cat *.h | grep NULL | grep define
You don't need to write a script for this. IHBT
4
Name:
Anonymous
2010-09-16 16:46
(|\s|\s\s|\s\s\s|\s\s\s\s|\s\s\s\s\s|\s\s\s\s\s\s|\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s)#define(\s|\s\s|\s\s\s|\s\s\s\s|\s\s\s\s\s|\s\s\s\s\s\s|\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s)NULL(\s|\s\s|\s\s\s|\s\s\s\s|\s\s\s\s\s|\s\s\s\s\s\s|\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s|\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s)
5
Name:
Anonymous
2010-09-16 16:50
6
Name:
Anonymous
2010-09-16 17:12
>>4
Oh man, if only a regex could use some modifier somehow to cover any number of whitespace characters
!
Forget it, it'll never happen.
7
Name:
Anonymous
2010-09-16 17:43
>>1
$ man grep,
``faggot'' .
8
Name:
Anonymous
2010-09-16 17:47
>>7
U MENA
$ grep '\[0 or more whitespace characters] \+ #define \+ \[1 or more whitespace characters\] \+ NULL \+ \[1 or more whitespace characters\]' file.c
?
9
Name:
Anonymous
2010-09-16 17:52
>>8
GREP ZERO OR MORE WHITESPACE CHARACTERS PLUS DEFINE PLUS ONE OR MORE WHITESPACE CHARACTERS PLUS NULL PLUS ONE OR MORE WHITESPACE CHARACTERS MY\ ANUS.c
10
Name:
Anonymous
2010-09-16 20:09
\s*#define\s+NULL\s+
11
Name:
sage
2010-09-16 20:30
>>10
the greps, they do nothing
12
Name:
Anonymous
2010-09-16 22:46
>>10
Someone always has to miss the point.
13
Name:
Anonymous
2010-09-16 22:52
>>10
\s*#define\s+?NULL\s+?
OMG OPTIMIZED
14
Name:
Anonymous
2010-09-17 9:23
"[[:space:]]?#define[[:space:]]+NULL[[:space:]]+"
I am doing it right.
15
Name:
Anonymous
2010-09-17 13:19
16
Name:
Anonymous
2010-09-17 17:42
>>14
EXPERT POSIX PROGRAMMER
17
Name:
sage
2010-09-17 18:57
18
Name:
Anonymous
2010-09-18 17:41
19
Name:
Anonymous
2010-09-18 17:46
>>18
Bracket expressions are a feature of basic regular expressions. You don't need
egrep for it.
20
Name:
sage
2010-09-19 6:06
>>19
to run it in grep you need --extended-regexp which means you're egrepping.
21
Name:
Anonymous
2010-09-19 11:54
>>20
No, you don't. Bracket expressions are a feature of
basic regular expressions.
22
Name:
Anonymous
2010-09-20 7:20
>>21
Yes, you do. At least in
Ubuntu .
23
Name:
Anonymous
2010-09-20 7:31
>>22
[hma@anuslandia:~] cat jews
sdf
hma
aSdf
234
xcv
sdfg34
anuses
[hma@anuslandia:~] grep "[[:digit:]]" jews
234
sdfg34
[hma@anuslandia:~] uname -a
Linux anuslandia 2.6.31-16-generic #53-Ubuntu SMP Tue Dec 8 04:01:29 UTC 2009 i686 GNU/Linux
24
Name:
Anonymous
2010-09-20 8:24
$ export POSIXLY_CORRECT=1
$ echo baaaaaaab | grep "ba+b"
$ echo baaaaaaab | grep -E "ba+b"
baaaaaaab
$ grep --version | head -n1
GNU grep 2.6.3
25
Name:
Anonymous
2010-09-20 9:28
ronc@piggy:~$ grep --with-filename --line-number --recursive "[[:space:]]?#define[[:space:]]+NULL[[:space:]]+" /usr/include/
ronc@piggy:~$ grep --with-filename --line-number --recursive --extended-regexp "[[:space:]]?#define[[:space:]]+NULL[[:space:]]+" /usr/include/
/usr/include/linux/stddef.h:8:#define NULL 0
/usr/include/linux/stddef.h:10:#define NULL ((void *)0)
ronc@piggy:~$ uname -a
Linux piggy 2.6.32-24-generic #43-Ubuntu SMP Thu Sep 16 14:17:33 UTC 2010 i686 GNU/Linux
26
Name:
Anonymous
2010-09-20 9:46
Sheesh.
NULL = (void *)0
/thread.