extracting first letter of a String with Regex -


I am new to RegEx and I want to be able to search and replace special texts in my text files. I have been successful in most searches but it is one that I could not hang it. I think I should look around / look around but the device I am using is syntax error. Basically there is data in my file here

[2010-01-15 06: 18: 10.203] [0x00001388] [SHDNT] Shutdown calculation down = 2/5

[2010 [0x00001388] [SHDNT] Shutdown calculation down = 3/5

And I want to be able to capture in my search '[' and ']' All around Side date I thought about using some parameters ('[' [[0-9] [0-9] after two digits means) and with '' '' 'moving forward'. ' ['[0- 9] [0- 9]' mean dot and 3digits).

I tried to do this but it gives the error [[(=? [0-9] [0-9]) Search for the first. Do not have permission to allow me? Just after the brackets

How should I search?

Thank you in advance

Add edit

To clarify this, I do not use RegEx with any programming language I am using a text editor that has search and changes the function which allows pattern search. So I want to remove square bracket around the date. But do not change anything else in my file

The following regular expression:

 < Code> ^ \ [([^ \]] +) \]  

The string plus square will capture the date at the beginning of the bracket, and in in the virtual brackets The accessories will put a group that can be removed from itself.

Note that your text editor may have slightly different syntax how it breaks:

  ^ = line / string start [\\] = literal [ And] character () = indicates a group [^ \]] = To catch any match character _ excit_ a close bracket (this match keeps very greedy) + = one or more of the last  

Edit: Believes that your regex feature group (which is the highest). The easiest way to explain groups is to show how they work with such an engine. In Python interpreter:

  & gt; & Gt; & Gt; Import re & gt; & Gt; & Gt; S = '[2010-01-15 06: 18: 10.203] [0x00001388] [SHDNT] ...' & gt; & Gt; & Gt; R = re.compile (r '^ \ [([^ \]] +) \]') & gt; & Gt; & Gt; M = r.search (s)  

This creates a regular expression object and searches for a string that matches that text, the result is given in a match object: / P>

  & gt; & Gt; & Gt; M & LT; _sre.SRE_Match object 0x1004d9558 & gt;  

To get the complete of the matched text, call the group on the Python Convention match object: / P>

  & gt; & Gt; & Gt; In order to get the goods in brackets, I pass the number of the group which is: M.group () '[2010-01-15 06: 18: 10.203]'  

I want in this case only one group of feet, so only one group):

  gt; & Gt; If I replace one instead of a search, then I use the  sub  I & ldquo; M.group (1) '2010-01-15 06: 18: 10.203' ' 

ceremony The sub string wants to replace complete , after the input string, and if a match is found, returns the string with the replacement:

  & gt; & Gt; & Gt; Spam spam [0x00001388] [SHDNT] ... ' 

However, the replacement string supports sequential escape sequences which refer to specific values, the group's replacement of match-occupied groups Is indicated by \ N , where N is the number of the group. Therefore:

  & gt; & Gt; & Gt; R.sub (r '\ 1', s) '2010-01-15 06: 18: 10.203 [0x00001388] [SHDNT] ...'  

What you want is .


Comments