0

Hopefully someone can help me out. Been all over google now.

I'm doing some zone-ocr of documents, and want to extract some text with regex. It is always like this:

"Til: Name Name Name org.nr 12323123".

I want to extract the name-part, it can be 1-4 names, but "Til:" and "org.nr" is always before and after.

Anyone?

1
  • Alot. I'm bit of a regex-rookie, so have just tried to edit expressions that have done something similar without any luck. Commented Aug 15, 2011 at 7:15

2 Answers 2

1

If you can't use capturing groups (check your documentation) you can try this:

(?<=Til:).*?(?=org\.nr)

This solution is using look behind and lookahead assertions, but those are not supported from every regex flavour. If they are working, this regex will return only the part you want, because the parts in the assertions are not matched, it checks only if the patterns in the assertions are there.

Sign up to request clarification or add additional context in comments.

Comments

1

Use the pattern:

Til:(.*)org\.nr

Then take the second group to get the content between the parenthesis.

5 Comments

This give me the value with "Til:" and "org.nr". I need it without, as this is to extract text from a document to metadata.
Like I said, just read out the second group text. That won't have the start/end bits.
@matshako what language are you using? The result you want is in the first capturing group (because of the ()), how you access this group depends on your language.
How will I be able to do that, when I only can run one regex on the original document, and not on the results?
This is a zone-ocr-program, were I can mark a certain zone of a scanned document and search for text to extract into different metadata-tags. Therefor I don't know the language. And I'm only getting the initial results stored in a metatag without my control, so I don't know if I'm able to read any groups.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.