---
title: colRegex
description: "DataFrame.colRegex method in PySpark: Selects column based on the column name specified as a regex and returns it as Column."
canonical_url: https://docs.databricks.com/gcp/en/pyspark/reference/classes/dataframe/colRegex
---

# colRegex

Selects column based on the column name specified as a regex and returns it as `Column`.

## Syntax

```
colRegex(colName: str)
```

## Parameters

| Parameter | Type | Description                               |
| --------- | ---- | ----------------------------------------- |
| `colName` | str  | string, column name specified as a regex. |

## Returns

`Column`

## Examples

```python
df = spark.createDataFrame([("a", 1), ("b", 2), ("c",  3)], ["Col1", "Col2"])
df.select(df.colRegex("`(Col1)?+.+`")).show()
# +----+
# |Col2|
# +----+
# |   1|
# |   2|
# |   3|
# +----+
```
