> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/s/strip_comments_from_a_string.md).

# Strip comments from a string

```ruby
func strip_comment(s) {
    (s - %r'[#;].*').strip
}
 
[" apples, pears # and bananas",
 " apples, pears ; and bananas",
 " apples, pears "].each { |s|
    say strip_comment(s).dump;
}
```

#### Output:

```
"apples, pears"
"apples, pears"
"apples, pears"
```
