regex - Match a string and the 5 characters before and after -


i need match string one or two , 5 characters before , after

with following text in input

lorem ipsum dummy 1 text of printing , typesetting industry. lorem ipsum has been industry's standard dummy text ever since 1500s, when unknown printer took galley of type , scrambled make type specimen 2 book. has survived not 5 centuries, leap electronic typesetting, remaining unchanged. popularised in 1960s release of letraset sheets containing lorem ipsum passages, , more desktop publishing software aldus pagemaker including versions of lorem ipsum.

the output should be

  • ummy 1 text
  • imen 2 book

the regex should works scan method in ruby

this regex should work:

.{5}(?:one|two).{5} 

if want word boundaries then:

.{5}\b(?:one|two)\b.{5} 

live demo (ruby): http://www.rubular.com/r/acdofxmx31


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -