Regex for LAS entries

142 Views Asked by At

I am very bad with RegEx. Can anyone help me getting RegEx for this pattern.

Here is the pattern

(Words).(Single Character, can be empty)(white spaces)(words, can be empty):(Words, can be empty)

Here are the examples

VERS. 2.00: Ver 2.00
WRAP. NO:
STRT.F                  4501.0000:START DEPTH
WELL. C5 1H:WELL
FTG GTG. :LOCATION FOOTAGE DESCRIPTION

Update 1:

Here is what I have done.

string re1 = "((?:[a-z][a-z]+))";   // Word 1
string re2 = ".*?"; // Non-greedy match on filler
string re3 = "(\\.)";   // Any Single Character 1
string re4 = "(.)"; // Any Single Character 2
string re5 = "(\\s+)";  // White Space 1
string re6 = "((?:[a-z][a-z]+))";   // Word 2
string re7 = ".*?"; // Non-greedy match on filler
string re8 = "(:)"; // Any Single Character 3
string re9 = ".*?"; // Non-greedy match on filler
string re10 = "(?:[a-z][a-z]+)";    // Uninteresting: word
string re11 = ".*?";    // Non-greedy match on filler
string re12 = "((?:[a-z][a-z]+))";  // Word 3

Regex r = new Regex(re1 + re2 + re3 + re4 + re5 + re6 + re7 + re8 + re9 + re10 + re11 + re12, RegexOptions.IgnoreCase | RegexOptions.Singleline);

Update 2:

Okay. I have tried something new. Here is my regex.

(\.)(.)(\s+)(4501.0000)(:)

Here is the input.

STRT DTG.F                  4501.0000:START DEPTH

And here is output.

STRT DTG
.
F

4501.0000
:
START DEPTH

Now I need to only replace 4501.0000 with regex for sentence (e.g. "some text" or "some more text"),

2

There are 2 best solutions below

3
On BEST ANSWER

The header section of the LAS file (generally) has this kind of format.

<MNEM> .<UNIT> <DATA> : <DESCRIPTION>

The regex can be like this.

^([\w\s]*)\s*\.([^ ]*)\s*([^:]*)\s*:(.*)$

Explanation

^         -> beginning of line
([\w\s]*) ->   1st group, MNEM (take words and/or space)
\s*       -> space
\.        -> period delimiter
([^ ]*)     ->   2nd group, UNIT (take everything until it sees space)
\s*       -> space
([^:]*)   ->   3rd group, DATA (take everything until it sees colon)
\s*       -> space
:         -> colon delimiter
(.*)      ->   4th group, DESCRIPTION (take everything)
$         -> end of line

DEMO

0
On

use \s or " " to include whitespace as well. Something like

     ((?:[a-z][a-z\s]+))

or

      ((?:[a-z][a-z ]+))