# RegEx help (select to end of line)

**URL:** https://boards.straightdope.com/t/regex-help-select-to-end-of-line/715218
**Category:** Factual Questions
**Created:** [March 17, 2015, 5:28pm UTC](https://boards.straightdope.com/t/regex-help-select-to-end-of-line/715218 "2015-03-17T17:28:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Amateur\_Barbarian](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@Amateur\_Barbarian](https://boards.straightdope.com/u/Amateur_Barbarian)
#### Post date: [March 17, 2015, 5:28pm UTC](https://boards.straightdope.com/t/regex-help-select-to-end-of-line/715218/1 "2015-03-17T17:28:16Z")

</div>

Damn, I’ve gotten rusty at regex. Modern search tools are just too darn smart and handy.

Can someone without Google-induced lazy forgettery tell me how to search and select from **[beginning of line][short string][to end of line including newline]**?

---

<div class="post-metadata">

### Author: ![gnoitall](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@gnoitall](https://boards.straightdope.com/u/gnoitall)
#### Post date: [March 17, 2015, 6:07pm UTC](https://boards.straightdope.com/t/regex-help-select-to-end-of-line/715218/2 "2015-03-17T18:07:01Z")

</div>

> [@Amateur\_Barbarian](#):
>
> Damn, I’ve gotten rusty at regex. Modern search tools are just too darn smart and handy.
> 
> Can someone without Google-induced lazy forgettery tell me how to search and select from **[beginning of line][short string][to end of line including newline]**?

If the beginning-of-line anchor is important, I’d use (“foobar” is the short string in your example

> [@](#):
>
> ^foobar.\*$

Beginning-of-line anchor, string, “skip anything”, end-of-line anchor

---

<div class="post-metadata">

### Author: ![dstarfire](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dstarfire/32/5762_2.png) [@dstarfire](https://boards.straightdope.com/u/dstarfire)
#### Post date: [March 18, 2015, 11:12pm UTC](https://boards.straightdope.com/t/regex-help-select-to-end-of-line/715218/3 "2015-03-18T23:12:22Z")

</div>

ummm, does the string immediately follow the start of a line? If it doesn’t, we’d have to do a “match anything except”, and I’m pretty sure you can only do that when the exception (in this case, it’s the first char of the string we’re searching for) is a single character.

Here’s my collection of handy regex tools:  
[Regex Cheat sheet](http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/)  
[Regex tester](http://www.regexr.com/)  
[Another cheat sheet](http://www.night-ray.com/regex.pdf).\* (slightly more comprehensive)\* warning: pdf

---

<div class="post-metadata">

### Author: ![Simplicio](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Simplicio](https://boards.straightdope.com/u/Simplicio)
#### Post date: [March 18, 2015, 11:18pm UTC](https://boards.straightdope.com/t/regex-help-select-to-end-of-line/715218/4 "2015-03-18T23:18:10Z")

</div>

^ is the beginning of line ancor  
shortstring is interpreted literally  
.\* matches any number of other characters  
$ is the end of line anchor.

So / ^shortstring.\*$ /
