# How to remove all w

**URL:** <https://discourse.julialang.org/t/how-to-remove-all-w/46152>\
**Category:** General Usage\
**Created:** [September 6, 2020, 5:08pm UTC](https://discourse.julialang.org/t/how-to-remove-all-w/46152 "2020-09-06T17:08:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [September 6, 2020, 5:08pm UTC](https://discourse.julialang.org/t/how-to-remove-all-w/46152/1 "2020-09-06T17:08:13Z")

</div>

how to remove all two-letter words from an Array String? the numbers remain.  
data like this:

```julia
julia> baza1[:,5]
1074955-element Array{String,1}:
 "test"
 "mm gastro"
 "mm gastro"
 "mm gastro"
 "pps ps sc"
"00-254"
"00asd asda"

```

mm ps sc to remove!

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [September 6, 2020, 5:16pm UTC](https://discourse.julialang.org/t/how-to-remove-all-w/46152/2 "2020-09-06T17:16:18Z")

</div>

From a little bit of debugging on [regex101.com](http://regex101.com) I came up with

```julia
(^|\s)([a-z][a-z])(\s|$)

```

where the second capture is those two letter words you don’t want.

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [September 6, 2020, 5:27pm UTC](https://discourse.julialang.org/t/how-to-remove-all-w/46152/3 "2020-09-06T17:27:27Z")

</div>

An exact answer would depend on more detail, like what exactly you want to consider as words, and what to do with the whitespace around words you removed (e.g., what should be the output for `"abc de\tfg,\nhi!"`?).  
Here’s a regex-based solution that keeps all whitespace:

```julia
julia> replace("foo bar 12 ab cd αβ 34", r"\b\p{L}{2}\b"=>"")
"foo bar 12 34"

```

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [September 6, 2020, 5:28pm UTC](https://discourse.julialang.org/t/how-to-remove-all-w/46152/4 "2020-09-06T17:28:56Z")

</div>

It would be very helpful if you could include what the desired output would be, given your vector.

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [September 6, 2020, 11:42pm UTC](https://discourse.julialang.org/t/how-to-remove-all-w/46152/5 "2020-09-06T23:42:21Z")

</div>

Try  
`(?<=\s|^)\w{2}(?=\s|$)`

---

<div class="post-metadata">

**Author:** ![eliassno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eliassno/32/18917_2.png) [@eliassno](https://discourse.julialang.org/u/eliassno)\
**Post date:** [September 7, 2020, 12:40am UTC](https://discourse.julialang.org/t/how-to-remove-all-w/46152/6 "2020-09-07T00:40:16Z")

</div>

> [@danielw2904](#):
>
> (?\<=\s|^)\w{2}(?=\s|$)

Note that this would match `00` in

```plaintext
00 asd asda

```

but it’s unclear from the provided examples if that’s the desired output.

* * *

Maybe try

```julia
julia> baza1 = ["test", "mm gastro", "mm gastro", "mm gastro", "pps ps sc", "00-254", "00asd asda", "00 asd asda"];

julia> replace.(baza1, r"(?<=\s|^)\D{2}(?=\s|$)"=>"")
8-element Array{String,1}:
 "test"
 " gastro"
 " gastro"
 " gastro"
 "pps "
 "00-254"
 "00asd asda"
 "00 asd asda"

```

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [September 7, 2020, 7:26am UTC](https://discourse.julialang.org/t/how-to-remove-all-w/46152/7 "2020-09-07T07:26:52Z")

</div>

Just the same Array{String} but only without the shor words  
repalce! ?  
Paul  
W dniu 2020-09-06 o 19:33, Matt Helm via JuliaLang pisze:
