-3

I am given a task that will require regex to find a string out of a paragraph. I need to find a string that looks something.like.this but is not limited to looking.something.like.this.also.

Using the paragraph above as an example, this expression would have pulled out "something.like.this" and "looking.something.like.this.also"

Must me A-z, no =+[]{}\/?*&^%$#@!*, can include .()-

I thought about checking to see if there are multiple periods between spaces.

TFrost
  • 769
  • 2
  • 12
  • 31
Bernie
  • 107
  • 1
  • 2
  • 9

1 Answers1

1

Is this regex what you're looking for?

(?:[A-Za-z(\)-]+(?:\.[A-Za-z\(\)-]+)+){2,}

Additional criterias in comments

  • Cannot match ... .

    This would also match ... which is not included in the OP's requirements. – juharr

    @Zsw i didnt think about it, but @juharr is correct, i cannot have ... – Bernie

  • Cannot match consecutive periods.

    What about consecutive periods like this..has...multiple....periods - juharr

    @juharr i should also ignore this, but it will be highly unlikely that will appear in any of the text it will run against. – Bernie

  • Cannot match one.two.

    @Zsw one.two cannot be matched. I found using [A-Za-z.()-]+.[A-Za-z.()-]+.[A-Za-z.()-]+ works for this, but how do i ignore the ... or this...this..this? – Bernie

Zsw
  • 3,920
  • 4
  • 29
  • 43
  • YES! this works, by chance can you provide an explanation? – Bernie Aug 18 '15 at 12:59
  • 1
    does not match _"looking.something.like.this.also"_. Consider editing. Also incorrectly matches `miss.piggy.has.really.big.chubby.fingers.and.cant.use.a.regular.rotary.dial.telephone` –  Aug 18 '15 at 12:59
  • @MickyDuncan +1 for example! Is there a limit of characters regex will find? – Bernie Aug 18 '15 at 13:05
  • @MickyDuncan How is the second example an incorrect match? It seems to fit with Bernie's requirement. Also, after adding a `g` flag, it does match `looking.something.like.this.also`. https://regex101.com/r/sC2yC6/2 – Zsw Aug 18 '15 at 13:07
  • 1
    This would also match `...` which is not included in the OP's requirements. – juharr Aug 18 '15 at 13:11
  • @juharr It would, but the OP said that the strings `can include .()`, so it should fit the requirement, I think. Unless Bernie would like to clarify? – Zsw Aug 18 '15 at 13:13
  • 1
    @Zsw i didnt think about it, but @juharr is correct, i cannot have `...` – Bernie Aug 18 '15 at 13:15
  • @juharr i should also ignore this, but it will be highly unlikely that will appear in any of the text it will run against. – Bernie Aug 18 '15 at 13:20
  • To add to this. i also can not have `site.com` match this. – Bernie Aug 18 '15 at 13:25
  • @Bernie Why not? `site.com` seems to fit with your requirement. Is it specifically that you want to ignore `.com`? Or that `one.two` in general cannot be matched? – Zsw Aug 18 '15 at 13:27
  • @Zsw `one.two` cannot be matched. I found using `[A-Za-z\.\(\)-]+\.[A-Za-z\.\(\)-]+\.[A-Za-z\.\(\)-]+` works for this, but how do i ignore the `...` or `this...this..this`? – Bernie Aug 18 '15 at 13:30
  • @Bernie My new edit should satisfy all your requirements now. – Zsw Aug 18 '15 at 13:32